diff options
author | Ben Gertzfield <beng@fb.com> | 2016-04-29 12:57:48 -0700 |
---|---|---|
committer | Ben Gertzfield <beng@fb.com> | 2016-04-29 15:15:09 -0700 |
commit | 3400727ffff0c0ab5b834632fea91948f7f43d66 (patch) | |
tree | d652b9b572194f3cd33eecbc5192ece78ffa3482 /tests/test.cpp | |
parent | 77742a3fba232a256b54c8e6e2c2c8de9f8d1834 (diff) | |
download | flatbuffers-3400727ffff0c0ab5b834632fea91948f7f43d66.tar.gz flatbuffers-3400727ffff0c0ab5b834632fea91948f7f43d66.tar.bz2 flatbuffers-3400727ffff0c0ab5b834632fea91948f7f43d66.zip |
Fix undefined behavior in CheckBitsFit bit-shift on size_t
Diffstat (limited to 'tests/test.cpp')
-rw-r--r-- | tests/test.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test.cpp b/tests/test.cpp index 4c3aa543..e636f1f3 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -819,6 +819,33 @@ void EnumStringsTest() { "{ F:[ \"E.C\", \"E.A E.B E.C\" ] }"), true); } +void IntegerOutOfRangeTest() { + TestError("table T { F:byte; } root_type T; { F:256 }", + "constant does not fit"); + TestError("table T { F:byte; } root_type T; { F:-257 }", + "constant does not fit"); + TestError("table T { F:ubyte; } root_type T; { F:256 }", + "constant does not fit"); + TestError("table T { F:ubyte; } root_type T; { F:-257 }", + "constant does not fit"); + TestError("table T { F:short; } root_type T; { F:65536 }", + "constant does not fit"); + TestError("table T { F:short; } root_type T; { F:-65537 }", + "constant does not fit"); + TestError("table T { F:ushort; } root_type T; { F:65536 }", + "constant does not fit"); + TestError("table T { F:ushort; } root_type T; { F:-65537 }", + "constant does not fit"); + TestError("table T { F:int; } root_type T; { F:4294967296 }", + "constant does not fit"); + TestError("table T { F:int; } root_type T; { F:-4294967297 }", + "constant does not fit"); + TestError("table T { F:uint; } root_type T; { F:4294967296 }", + "constant does not fit"); + TestError("table T { F:uint; } root_type T; { F:-4294967297 }", + "constant does not fit"); +} + void UnicodeTest() { flatbuffers::Parser parser; TEST_EQ(parser.Parse("table T { F:string; }" @@ -878,6 +905,7 @@ int main(int /*argc*/, const char * /*argv*/[]) { ErrorTest(); ScientificTest(); EnumStringsTest(); + IntegerOutOfRangeTest(); UnicodeTest(); UnknownFieldsTest(); |