mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
Fixed potential strict-aliasing violation in big-endian code.
Also added a test. Tested on: Linux. Change-Id: I7b3230f8f6043eec139d5e3e8c9cb45814124274
This commit is contained in:
@@ -1803,6 +1803,16 @@ void TypeAliasesTest()
|
||||
TEST_EQ(sizeof(ta->f64()), 8);
|
||||
}
|
||||
|
||||
void EndianSwapTest() {
|
||||
TEST_EQ(flatbuffers::EndianSwap(static_cast<int16_t>(0x1234)),
|
||||
0x3412);
|
||||
TEST_EQ(flatbuffers::EndianSwap(static_cast<int32_t>(0x12345678)),
|
||||
0x78563412);
|
||||
TEST_EQ(flatbuffers::EndianSwap(static_cast<int64_t>(0x1234567890ABCDEF)),
|
||||
0xEFCDAB9078563412);
|
||||
TEST_EQ(flatbuffers::EndianSwap(flatbuffers::EndianSwap(3.14f)), 3.14f);
|
||||
}
|
||||
|
||||
int main(int /*argc*/, const char * /*argv*/[]) {
|
||||
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && \
|
||||
defined(_MSC_VER) && defined(_DEBUG)
|
||||
@@ -1866,6 +1876,7 @@ int main(int /*argc*/, const char * /*argv*/[]) {
|
||||
ConformTest();
|
||||
ParseProtoBufAsciiTest();
|
||||
TypeAliasesTest();
|
||||
EndianSwapTest();
|
||||
|
||||
FlexBuffersTest();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user