Silence false positive "-Wstringop-overflow" on GCC 10.0 to 11.0 (#6020)

This commit is contained in:
Vasyl Gello
2020-07-06 18:38:06 +03:00
committed by GitHub
parent 36fbe6f13e
commit 515a4052a7

View File

@@ -381,6 +381,13 @@ T ReadScalar(const void *p) {
return EndianScalar(*reinterpret_cast<const T *>(p));
}
// See https://github.com/google/flatbuffers/issues/5950
#if (FLATBUFFERS_GCC >= 100000) && (FLATBUFFERS_GCC < 110000)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-overflow"
#endif
template<typename T>
// UBSAN: C++ aliasing type rules, see std::bit_cast<> for details.
__supress_ubsan__("alignment")
@@ -393,6 +400,10 @@ template<typename T> __supress_ubsan__("alignment") void WriteScalar(void *p, Of
*reinterpret_cast<uoffset_t *>(p) = EndianScalar(t.o);
}
#if (FLATBUFFERS_GCC >= 100000) && (FLATBUFFERS_GCC < 110000)
#pragma GCC diagnostic pop
#endif
// 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).