Skip to content

Commit 0223d11

Browse files
committed
505f410: tools/makeBinDump: explicit overloads for unsigned/signed/float to avoid UB (arm64)
1 parent fc7ff33 commit 0223d11

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

prog/tools/sharedInclude/libTools/util/makeBindump.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,8 @@ class BinDumpSaveCB
457457
}
458458
void writeReal(float v) { return writeFloat32e(v); }
459459
void writeInt32e(unsigned v) { cwr.writeInt(WRITE_BE ? le2be32(v) : v); }
460+
void writeInt32e(signed v) { writeInt32e(unsigned(v)); }
461+
void writeInt32e(float v) { writeInt32e(unsigned(int(floorf(v)))); }
460462
void writeE3dColorE(E3DCOLOR c) { cwr.writeInt(WRITE_BE ? le2be32(c) : (uint32_t)c.u); }
461463
void writePtr64e(unsigned ptr_ofs)
462464
{
@@ -489,21 +491,29 @@ class BinDumpSaveCB
489491
cwr.write(&v, 8);
490492
}
491493
void writeInt16e(unsigned v) { cwr.writeIntP<2>(WRITE_BE ? le2be16(v) : v); }
494+
void writeInt16e(signed v) { writeInt16e(unsigned(v)); }
495+
void writeInt16e(float v) { writeInt16e(unsigned(int(floorf(v)))); }
492496
void writeInt8e(unsigned v) { cwr.writeIntP<1>(v); }
497+
void writeInt8e(signed v) { writeInt8e(unsigned(v)); }
498+
void writeInt8e(float v) { writeInt8e(unsigned(int(floorf(v)))); }
493499
void writeInt16eAt(unsigned v, int ofs)
494500
{
495501
int pos = tell();
496502
seekto(ofs);
497503
cwr.writeIntP<2>(WRITE_BE ? le2be16(v) : v);
498504
seekto(pos);
499505
}
506+
void writeInt16eAt(signed v, int ofs) { writeInt16eAt(unsigned(v), ofs); }
507+
void writeInt16eAt(float v, int ofs) { writeInt16eAt(unsigned(int(floorf(v))), ofs); }
500508
void writeInt32eAt(unsigned v, int ofs)
501509
{
502510
int pos = tell();
503511
seekto(ofs);
504512
cwr.writeInt(WRITE_BE ? le2be32(v) : v);
505513
seekto(pos);
506514
}
515+
void writeInt32eAt(signed v, int ofs) { writeInt32eAt(unsigned(v), ofs); }
516+
void writeInt32eAt(float v, int ofs) { writeInt32eAt(unsigned(int(floorf(v))), ofs); }
507517
void writeDwString(const char *s)
508518
{
509519
int len = s ? (int)strlen(s) : 0;

0 commit comments

Comments
 (0)