String safety (#1548)

* Array size UB fixes

* Fix ShieldD

* Remove (almost) all unsafe strcpy calls

Bunch of macros. C arrays are easy enough and just need a different call. For various cases where a char* is passed around bare, I've made a TEXT_SPAN macro that can store a length too for bounds checking.

* Move crash handling in safe string operations to separate TU

* strcat safe version

* sprintf made safe too

* Fix compile
This commit is contained in:
Pieter-Jan Briers
2026-05-24 18:43:00 +02:00
committed by GitHub
parent af162bbd0a
commit a6376368ee
100 changed files with 781 additions and 546 deletions
+2 -2
View File
@@ -351,13 +351,13 @@ const char* daSetBgObj_c::getArcName(fopAc_ac_c* i_this) {
u32 r30 = fopAcM_GetParam(i_this);
u16 r29 = fopAcM_GetParam(i_this);
sprintf(arcName, "@bg%04x", r29);
SAFE_SPRINTF(arcName, "@bg%04x", r29);
if (DEBUG && r30 & 0x80000000) {
OS_REPORT("\e[43;30m旧仕様の地形ユニットMoveBGが残っています!!!\n\e[m");
u16 r28 = r30 >> 12 & 0x1FF;
u16 r27 = r30 & 0xFFF;
sprintf(arcName, "@%03x%03x", r28, (u16)r27);
SAFE_SPRINTF(arcName, "@%03x%03x", r28, (u16)r27);
}
return arcName;
}