summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaruch Siach <baruch@tkos.co.il>2018-06-10 21:28:18 +0300
committerPeter Korsgaard <peter@korsgaard.com>2018-06-12 08:41:21 +0200
commit82818284ed77276902b49f4b82106faf43b89003 (patch)
tree4fc56bf261036598be1cae0853a21a56e97e68c7
parent2b88def5db35fc3f3b4e68c664c230bba33f0bb3 (diff)
downloadbuildroot-82818284ed77276902b49f4b82106faf43b89003.tar.gz
buildroot-82818284ed77276902b49f4b82106faf43b89003.zip
flatcc: fix build with gcc 8
gcc 8 enables a strncpy() warning. This breaks the build of flatcc that enables -Werror. Add upstream patch fixing the issue. Fixes: http://autobuild.buildroot.net/results/0e3/0e3a959855fad5899db184f7d2c960c89df03672/ http://autobuild.buildroot.net/results/d2c/d2c03bc253bdf135b0f31f3d1e6fd33f7d37d64b/ http://autobuild.buildroot.net/results/163/1636ec6ddad92add95f42451d941156451c6d936/ Cc: Joel Carlson <JoelsonCarl@gmail.com> Cc: Mikkel Fahnøe Jørgensen <mikkel@dvide.com> Signed-off-by: Baruch Siach <baruch@tkos.co.il> Reviewed-by: Joel Carlson <JoelsonCarl@gmail.com> Tested-by: Joel Carlson <JoelsonCarl@gmail.com> Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
-rw-r--r--package/flatcc/0001-Remove-strncpy-gcc-8-warning-add-flatbuffers_type_ha.patch138
1 files changed, 138 insertions, 0 deletions
diff --git a/package/flatcc/0001-Remove-strncpy-gcc-8-warning-add-flatbuffers_type_ha.patch b/package/flatcc/0001-Remove-strncpy-gcc-8-warning-add-flatbuffers_type_ha.patch
new file mode 100644
index 0000000000..28c0208891
--- /dev/null
+++ b/package/flatcc/0001-Remove-strncpy-gcc-8-warning-add-flatbuffers_type_ha.patch
@@ -0,0 +1,138 @@
+From c0df0b6fca4fa6bca114bba4df74f1b4e53124c0 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Mikkel=20Fahn=C3=B8e=20J=C3=B8rgensen?= <mikkel@dvide.com>
+Date: Sat, 9 Jun 2018 11:10:24 +0200
+Subject: [PATCH] Remove strncpy gcc-8 warning, add
+ flatbuffers_type_hash_from_string
+
+[baruch: drop CHANGELOG hunk]
+Signed-off-by: Baruch Siach <baruch@tkos.co.il>
+---
+Upstream status: commit c0df0b6fca4
+
+ include/flatcc/flatcc_identifier.h | 21 +++++++++++++++++++
+ .../reflection/flatbuffers_common_reader.h | 4 +---
+ src/compiler/codegen_c_reader.c | 4 +---
+ src/runtime/json_printer.c | 7 +++++--
+ src/runtime/verifier.c | 5 ++---
+ 6 files changed, 32 insertions(+), 11 deletions(-)
+
+diff --git a/include/flatcc/flatcc_identifier.h b/include/flatcc/flatcc_identifier.h
+index cd918cb42b48..31af3074f4db 100644
+--- a/include/flatcc/flatcc_identifier.h
++++ b/include/flatcc/flatcc_identifier.h
+@@ -77,6 +77,27 @@ static inline flatbuffers_thash_t flatbuffers_type_hash_from_identifier(const fl
+ (uint32_t)p[0] + (((uint32_t)p[1]) << 8) + (((uint32_t)p[2]) << 16) + (((uint32_t)p[3]) << 24) : 0;
+ }
+
++/*
++ * Convert a null terminated string identifier like "MONS" or "X" into a
++ * native type hash identifier, usually for comparison. This will not
++ * work with type hash strings because they can contain null bytes.
++ */
++static inline flatbuffers_thash_t flatbuffers_type_hash_from_string(const char *identifier)
++{
++ flatbuffers_thash_t h = 0;
++ const uint8_t *p = (const uint8_t *)identifier;
++
++ if (!p[0]) return h;
++ h += p[0];
++ if (!p[1]) return h;
++ h += p[1] << 8;
++ if (!p[2]) return h;
++ h += p[2] << 16;
++ /* No need to test for termination here. */
++ h += p[3] << 24;
++ return h;
++}
++
+ /*
+ * Computes the little endian wire format of the type hash. It can be
+ * used as a file identifer argument to various flatcc buffer calls.
+diff --git a/include/flatcc/reflection/flatbuffers_common_reader.h b/include/flatcc/reflection/flatbuffers_common_reader.h
+index dee44ad653f1..9604052685f6 100644
+--- a/include/flatcc/reflection/flatbuffers_common_reader.h
++++ b/include/flatcc/reflection/flatbuffers_common_reader.h
+@@ -464,9 +464,7 @@ static inline T N ## _ ## NK (N ## _struct_t t__tmp) { return t__tmp ? &(t__tmp-
+ /* If fid is null, the function returns true without testing as buffer is not expected to have any id. */
+ static inline int flatbuffers_has_identifier(const void *buffer, const char *fid)
+ { flatbuffers_thash_t id, id2 = 0; if (fid == 0) { return 1; };
+- strncpy((char *)&id2, fid, sizeof(id2));
+- /* Identifier strings are always considered little endian. */
+- id2 = __flatbuffers_thash_cast_from_le(id2);
++ id2 = flatbuffers_type_hash_from_string(fid);
+ id = __flatbuffers_thash_read_from_pe(((flatbuffers_uoffset_t *)buffer) + 1);
+ return id2 == 0 || id == id2; }
+ static inline int flatbuffers_has_type_hash(const void *buffer, flatbuffers_thash_t thash)
+diff --git a/src/compiler/codegen_c_reader.c b/src/compiler/codegen_c_reader.c
+index e3df74754344..559731050a15 100644
+--- a/src/compiler/codegen_c_reader.c
++++ b/src/compiler/codegen_c_reader.c
+@@ -748,9 +748,7 @@ static void gen_helpers(fb_output_t *out)
+ "/* If fid is null, the function returns true without testing as buffer is not expected to have any id. */\n"
+ "static inline int %shas_identifier(const void *buffer, const char *fid)\n"
+ "{ %sthash_t id, id2 = 0; if (fid == 0) { return 1; };\n"
+- " strncpy((char *)&id2, fid, sizeof(id2));\n"
+- " /* Identifier strings are always considered little endian. */\n"
+- " id2 = __%sthash_cast_from_le(id2);\n"
++ " id2 = %stype_hash_from_string(fid);\n"
+ " id = __%sthash_read_from_pe(((%suoffset_t *)buffer) + 1);\n"
+ " return id2 == 0 || id == id2; }\n"
+ "static inline int %shas_type_hash(const void *buffer, %sthash_t thash)\n"
+diff --git a/src/runtime/json_printer.c b/src/runtime/json_printer.c
+index 8fe248331f43..bc86d21f8f9d 100644
+--- a/src/runtime/json_printer.c
++++ b/src/runtime/json_printer.c
+@@ -20,6 +20,7 @@
+
+ #include "flatcc/flatcc_flatbuffers.h"
+ #include "flatcc/flatcc_json_printer.h"
++#include "flatcc/flatcc_identifier.h"
+
+ #include "flatcc/portable/pprintint.h"
+ #include "flatcc/portable/pprintfp.h"
+@@ -1008,6 +1009,9 @@ void flatcc_json_printer_struct_field(flatcc_json_printer_t *ctx,
+ /*
+ * Make sure the buffer identifier is valid before assuming the rest of
+ * the buffer is sane.
++ * NOTE: this won't work with type hashes because these can contain
++ * nulls in the fid string. In this case use null as fid to disable
++ * check.
+ */
+ static int accept_header(flatcc_json_printer_t * ctx,
+ const void *buf, size_t bufsiz, const char *fid)
+@@ -1020,8 +1024,7 @@ static int accept_header(flatcc_json_printer_t * ctx,
+ return 0;
+ }
+ if (fid != 0) {
+- strncpy((char *)&id2, fid, FLATBUFFERS_IDENTIFIER_SIZE);
+- id2 = __flatbuffers_thash_cast_from_le(id2);
++ id2 = flatbuffers_type_hash_from_string(fid);
+ id = __flatbuffers_thash_read_from_pe((uint8_t *)buf + offset_size);
+ if (!(id2 == 0 || id == id2)) {
+ RAISE_ERROR(bad_input);
+diff --git a/src/runtime/verifier.c b/src/runtime/verifier.c
+index 68dbc1b6fb0b..3b7c68cca4d7 100644
+--- a/src/runtime/verifier.c
++++ b/src/runtime/verifier.c
+@@ -10,6 +10,7 @@
+ #include "flatcc/flatcc_rtconfig.h"
+ #include "flatcc/flatcc_flatbuffers.h"
+ #include "flatcc/flatcc_verifier.h"
++#include "flatcc/flatcc_identifier.h"
+
+ /* Customization for testing. */
+ #if FLATCC_DEBUG_VERIFY
+@@ -110,9 +111,7 @@ static inline uoffset_t read_uoffset(const void *p, uoffset_t base)
+
+ static inline thash_t read_thash_identifier(const char *identifier)
+ {
+- flatbuffers_thash_t id = 0;
+- strncpy((char *)&id, identifier, sizeof(id));
+- return __flatbuffers_thash_cast_from_le(id);
++ return flatbuffers_type_hash_from_string(identifier);
+ }
+
+ static inline thash_t read_thash(const void *p, uoffset_t base)
+--
+2.17.1
+
OpenPOWER on IntegriCloud