From 57ee742cb1d2a2902dd5e00af5da9293aa11326c Mon Sep 17 00:00:00 2001
From: yefeng <yefeng24@huawei.com>
Date: Wed, 17 Nov 2021 14:49:42 +0800
Subject: [PATCH 1/2] fix undefined behaviour

---
 include/flatbuffers/flatbuffers.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h
index e652e40..42c4fa8 100644
--- a/include/flatbuffers/flatbuffers.h
+++ b/include/flatbuffers/flatbuffers.h
@@ -1808,7 +1808,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));
   }
 
-- 
2.17.1

