Fix UB in CreateVectorOfStructs in case of an empty vector: avoid calling memcpy in this case (#6726)

This commit is contained in:
Daniil Nikolenko
2021-07-08 23:40:53 +03:00
committed by GitHub
parent 8f8196e136
commit bf3470c161

View File

@@ -1914,7 +1914,9 @@ class FlatBufferBuilder {
template<typename T>
Offset<Vector<const T *>> CreateVectorOfStructs(const T *v, size_t len) {
StartVector(len * sizeof(T) / AlignOf<T>(), AlignOf<T>());
PushBytes(reinterpret_cast<const uint8_t *>(v), sizeof(T) * len);
if (len > 0) {
PushBytes(reinterpret_cast<const uint8_t *>(v), sizeof(T) * len);
}
return Offset<Vector<const T *>>(EndVector(len));
}