mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
IterateValue: Use ReadScalar instead of unportable reinterpret_casts (#5209)
This fixes the testcase MiniReflectFlatBuffersTest.
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
6e2d530d61
commit
1b9d1b0110
@@ -122,58 +122,58 @@ inline void IterateValue(ElementaryType type, const uint8_t *val,
|
|||||||
soffset_t vector_index, IterationVisitor *visitor) {
|
soffset_t vector_index, IterationVisitor *visitor) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ET_UTYPE: {
|
case ET_UTYPE: {
|
||||||
auto tval = *reinterpret_cast<const uint8_t *>(val);
|
auto tval = ReadScalar<uint8_t>(val);
|
||||||
visitor->UType(tval, EnumName(tval, type_table));
|
visitor->UType(tval, EnumName(tval, type_table));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ET_BOOL: {
|
case ET_BOOL: {
|
||||||
visitor->Bool(*reinterpret_cast<const uint8_t *>(val) != 0);
|
visitor->Bool(ReadScalar<uint8_t>(val) != 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ET_CHAR: {
|
case ET_CHAR: {
|
||||||
auto tval = *reinterpret_cast<const int8_t *>(val);
|
auto tval = ReadScalar<int8_t>(val);
|
||||||
visitor->Char(tval, EnumName(tval, type_table));
|
visitor->Char(tval, EnumName(tval, type_table));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ET_UCHAR: {
|
case ET_UCHAR: {
|
||||||
auto tval = *reinterpret_cast<const uint8_t *>(val);
|
auto tval = ReadScalar<uint8_t>(val);
|
||||||
visitor->UChar(tval, EnumName(tval, type_table));
|
visitor->UChar(tval, EnumName(tval, type_table));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ET_SHORT: {
|
case ET_SHORT: {
|
||||||
auto tval = *reinterpret_cast<const int16_t *>(val);
|
auto tval = ReadScalar<int16_t>(val);
|
||||||
visitor->Short(tval, EnumName(tval, type_table));
|
visitor->Short(tval, EnumName(tval, type_table));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ET_USHORT: {
|
case ET_USHORT: {
|
||||||
auto tval = *reinterpret_cast<const uint16_t *>(val);
|
auto tval = ReadScalar<uint16_t>(val);
|
||||||
visitor->UShort(tval, EnumName(tval, type_table));
|
visitor->UShort(tval, EnumName(tval, type_table));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ET_INT: {
|
case ET_INT: {
|
||||||
auto tval = *reinterpret_cast<const int32_t *>(val);
|
auto tval = ReadScalar<int32_t>(val);
|
||||||
visitor->Int(tval, EnumName(tval, type_table));
|
visitor->Int(tval, EnumName(tval, type_table));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ET_UINT: {
|
case ET_UINT: {
|
||||||
auto tval = *reinterpret_cast<const uint32_t *>(val);
|
auto tval = ReadScalar<uint32_t>(val);
|
||||||
visitor->UInt(tval, EnumName(tval, type_table));
|
visitor->UInt(tval, EnumName(tval, type_table));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ET_LONG: {
|
case ET_LONG: {
|
||||||
visitor->Long(*reinterpret_cast<const int64_t *>(val));
|
visitor->Long(ReadScalar<int64_t>(val));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ET_ULONG: {
|
case ET_ULONG: {
|
||||||
visitor->ULong(*reinterpret_cast<const uint64_t *>(val));
|
visitor->ULong(ReadScalar<uint64_t>(val));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ET_FLOAT: {
|
case ET_FLOAT: {
|
||||||
visitor->Float(*reinterpret_cast<const float *>(val));
|
visitor->Float(ReadScalar<float>(val));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ET_DOUBLE: {
|
case ET_DOUBLE: {
|
||||||
visitor->Double(*reinterpret_cast<const double *>(val));
|
visitor->Double(ReadScalar<double>(val));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ET_STRING: {
|
case ET_STRING: {
|
||||||
|
|||||||
Reference in New Issue
Block a user