Fix big-endian build. (#5205)

For some reason, Offset<T> is being considered a scalar, which
causes EndianSwap to be passed an Offset<T>.  This doesn't work,
as it does not support types with non-trivial constructors.  This
change adds an overload to WriteScalar(), which works around this.
This commit is contained in:
Brian Wellington 2019-02-21 16:50:05 -08:00 committed by Wouter van Oortmerssen
parent 0cdacdfb35
commit a1f14005ab
1 changed files with 5 additions and 0 deletions

View File

@ -363,6 +363,11 @@ void WriteScalar(void *p, T t) {
*reinterpret_cast<T *>(p) = EndianScalar(t);
}
template<typename T> struct Offset;
template<typename T> __supress_ubsan__("alignment") void WriteScalar(void *p, Offset<T> t) {
*reinterpret_cast<uoffset_t *>(p) = EndianScalar(t.o);
}
// Computes how many bytes you'd have to pad to be able to write an
// "scalar_size" scalar if the buffer had grown to "buf_size" (downwards in
// memory).