Skip to content

Commit 1b9d1b0

Browse files
zeldinaardappel
authored andcommitted
IterateValue: Use ReadScalar instead of unportable reinterpret_casts (google#5209)
This fixes the testcase MiniReflectFlatBuffersTest.
1 parent 6e2d530 commit 1b9d1b0

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

include/flatbuffers/minireflect.h

+12-12
Original file line numberDiff line numberDiff line change
@@ -122,58 +122,58 @@ inline void IterateValue(ElementaryType type, const uint8_t *val,
122122
soffset_t vector_index, IterationVisitor *visitor) {
123123
switch (type) {
124124
case ET_UTYPE: {
125-
auto tval = *reinterpret_cast<const uint8_t *>(val);
125+
auto tval = ReadScalar<uint8_t>(val);
126126
visitor->UType(tval, EnumName(tval, type_table));
127127
break;
128128
}
129129
case ET_BOOL: {
130-
visitor->Bool(*reinterpret_cast<const uint8_t *>(val) != 0);
130+
visitor->Bool(ReadScalar<uint8_t>(val) != 0);
131131
break;
132132
}
133133
case ET_CHAR: {
134-
auto tval = *reinterpret_cast<const int8_t *>(val);
134+
auto tval = ReadScalar<int8_t>(val);
135135
visitor->Char(tval, EnumName(tval, type_table));
136136
break;
137137
}
138138
case ET_UCHAR: {
139-
auto tval = *reinterpret_cast<const uint8_t *>(val);
139+
auto tval = ReadScalar<uint8_t>(val);
140140
visitor->UChar(tval, EnumName(tval, type_table));
141141
break;
142142
}
143143
case ET_SHORT: {
144-
auto tval = *reinterpret_cast<const int16_t *>(val);
144+
auto tval = ReadScalar<int16_t>(val);
145145
visitor->Short(tval, EnumName(tval, type_table));
146146
break;
147147
}
148148
case ET_USHORT: {
149-
auto tval = *reinterpret_cast<const uint16_t *>(val);
149+
auto tval = ReadScalar<uint16_t>(val);
150150
visitor->UShort(tval, EnumName(tval, type_table));
151151
break;
152152
}
153153
case ET_INT: {
154-
auto tval = *reinterpret_cast<const int32_t *>(val);
154+
auto tval = ReadScalar<int32_t>(val);
155155
visitor->Int(tval, EnumName(tval, type_table));
156156
break;
157157
}
158158
case ET_UINT: {
159-
auto tval = *reinterpret_cast<const uint32_t *>(val);
159+
auto tval = ReadScalar<uint32_t>(val);
160160
visitor->UInt(tval, EnumName(tval, type_table));
161161
break;
162162
}
163163
case ET_LONG: {
164-
visitor->Long(*reinterpret_cast<const int64_t *>(val));
164+
visitor->Long(ReadScalar<int64_t>(val));
165165
break;
166166
}
167167
case ET_ULONG: {
168-
visitor->ULong(*reinterpret_cast<const uint64_t *>(val));
168+
visitor->ULong(ReadScalar<uint64_t>(val));
169169
break;
170170
}
171171
case ET_FLOAT: {
172-
visitor->Float(*reinterpret_cast<const float *>(val));
172+
visitor->Float(ReadScalar<float>(val));
173173
break;
174174
}
175175
case ET_DOUBLE: {
176-
visitor->Double(*reinterpret_cast<const double *>(val));
176+
visitor->Double(ReadScalar<double>(val));
177177
break;
178178
}
179179
case ET_STRING: {

0 commit comments

Comments
 (0)