mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
Add 'fsanitize=address,undefined' to tests and flatc targets (#5009)
* Add '-fsanitize' optional flags to flattests and flatc targets Control: -DFLATBUFFERS_CODE_SANITIZE=(ON | OFF | "=memory,undefined") Travis-CI: building with -DFLATBUFFERS_CODE_SANITIZE=ON * Fix -pie flag * Cleanup
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
bd20a60d6a
commit
0fb1d44bc4
@@ -1346,8 +1346,15 @@ void EnumNamesTest() {
|
||||
TEST_EQ_STR("Red", EnumNameColor(Color_Red));
|
||||
TEST_EQ_STR("Green", EnumNameColor(Color_Green));
|
||||
TEST_EQ_STR("Blue", EnumNameColor(Color_Blue));
|
||||
TEST_EQ_STR("", EnumNameColor(static_cast<Color>(-1)));
|
||||
TEST_EQ_STR("", EnumNameColor(static_cast<Color>(1000)));
|
||||
// Check that Color to string don't crash while decode a mixture of Colors.
|
||||
// 1) Example::Color enum is enum with unfixed underlying type.
|
||||
// 2) Valid enum range: [0; 2^(ceil(log2(Color_ANY))) - 1].
|
||||
// Consequence: A value is out of this range will lead to UB (since C++17).
|
||||
// For details see C++17 standard or explanation on the SO:
|
||||
// stackoverflow.com/questions/18195312/what-happens-if-you-static-cast-invalid-value-to-enum-class
|
||||
TEST_EQ_STR("", EnumNameColor(static_cast<Color>(0)));
|
||||
TEST_EQ_STR("", EnumNameColor(static_cast<Color>(Color_ANY-1)));
|
||||
TEST_EQ_STR("", EnumNameColor(static_cast<Color>(Color_ANY+1)));
|
||||
}
|
||||
|
||||
void EnumOutOfRangeTest() {
|
||||
|
||||
Reference in New Issue
Block a user