mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Avoid technically UB type punning when determining endianness
This commit is contained in:
parent
2fbd66c51c
commit
7ada02e21e
@ -38,13 +38,11 @@ namespace Detail {
|
||||
enum Arch { Big, Little };
|
||||
|
||||
static Arch which() {
|
||||
union _{
|
||||
int asInt;
|
||||
char asChar[sizeof (int)];
|
||||
} u;
|
||||
|
||||
u.asInt = 1;
|
||||
return ( u.asChar[sizeof(int)-1] == 1 ) ? Big : Little;
|
||||
int one = 1;
|
||||
// If the lowest byte we read is non-zero, we can assume
|
||||
// that little endian format is used.
|
||||
auto value = *reinterpret_cast<char*>(&one);
|
||||
return value ? Little : Big;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user