File tree 1 file changed +8
-3
lines changed
1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -385,6 +385,9 @@ bool deSerializeStringToStruct(std::string valstr,
385
385
}
386
386
387
387
388
+ // Casts *buf to a signed or unsigned fixed-width integer of 'w' width
389
+ #define SIGN_CAST (w, buf ) (is_unsigned ? *((u##w *) buf) : *((s##w *) buf))
390
+
388
391
bool serializeStructToString (std::string *out,
389
392
std::string format, void *value)
390
393
{
@@ -412,15 +415,15 @@ bool serializeStructToString(std::string *out,
412
415
case ' i' :
413
416
if (width == 16 ) {
414
417
bufpos += PADDING (bufpos, u16);
415
- os << *((u16 *) bufpos);
418
+ os << SIGN_CAST ( 16 , bufpos);
416
419
bufpos += sizeof (u16);
417
420
} else if (width == 32 ) {
418
421
bufpos += PADDING (bufpos, u32);
419
- os << *((u32 *) bufpos);
422
+ os << SIGN_CAST ( 32 , bufpos);
420
423
bufpos += sizeof (u32);
421
424
} else if (width == 64 ) {
422
425
bufpos += PADDING (bufpos, u64);
423
- os << *((u64 *) bufpos);
426
+ os << SIGN_CAST ( 64 , bufpos);
424
427
bufpos += sizeof (u64);
425
428
}
426
429
break ;
@@ -474,3 +477,5 @@ bool serializeStructToString(std::string *out,
474
477
475
478
return true ;
476
479
}
480
+
481
+ #undef SIGN_CAST
You can’t perform that action at this time.
0 commit comments