From ab01ae1620682ae214522d0be221685643fe6cf3 Mon Sep 17 00:00:00 2001 From: Stefan F <32997632+stefan301@users.noreply.github.com> Date: Mon, 28 Sep 2020 18:28:47 +0200 Subject: [PATCH] flatc should output a warning, when an attribute is attached more than once (#6146) * Added missing EndTable() call to VerifyObject() VerifyObject called VerifyTableStart() but not EndTable(). This made Verifier::VerifyComplexity() increase depth_ with each table, not with the depth of tables. https://groups.google.com/forum/#!topic/flatbuffers/OpxtW5UFAdg * Added Check to VerifyAlignment https://stackoverflow.com/questions/59376308/flatbuffers-verifier-returns-false-without-any-assertion-flatbuffers-debug-veri * Add GetStringView (Convenience function to get string_view from a String returning an empty string_view on null pointer) like GetString, GetCstring * flatc should warn, when an attribute is attached more than once. flatc.exe -b duplicate.fbs warning: duplicate.fbs(5, 36): warning: attribute already found: priority duplicate.fbs: namespace MyGame; attribute "priority"; table Monster (priority:1, priority:2) { } root_type Monster; --- include/flatbuffers/flatbuffers.h | 2 +- src/idl_parser.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h index 799f6478a..279afd545 100644 --- a/include/flatbuffers/flatbuffers.h +++ b/include/flatbuffers/flatbuffers.h @@ -592,7 +592,7 @@ static inline const char *GetCstring(const String *str) { static inline flatbuffers::string_view GetStringView(const String *str) { return str ? str->string_view() : flatbuffers::string_view(); } -#endif // FLATBUFFERS_HAS_STRING_VIEW +#endif // FLATBUFFERS_HAS_STRING_VIEW // Allocator interface. This is flatbuffers-specific and meant only for // `vector_downward` usage. diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index cd81d822d..566482d21 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -1559,7 +1559,7 @@ CheckedError Parser::ParseMetaData(SymbolTable *attributes) { name); NEXT(); auto e = new Value(); - attributes->Add(name, e); + if (attributes->Add(name, e)) Warning("attribute already found: " + name); if (Is(':')) { NEXT(); ECHECK(ParseSingleValue(&name, *e, true));