fix write out of bounds in smlua text utils (#13)

This commit is contained in:
Isaac0-dev 2024-03-29 13:56:15 +10:00 committed by GitHub
parent 974577f678
commit 7468ff001b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -35,7 +35,7 @@ void smlua_text_utils_init(void) {
// Course/Star names // Course/Star names
for (s16 courseNum = 0; courseNum < COURSE_END; courseNum++) { for (s16 courseNum = 0; courseNum < COURSE_END; courseNum++) {
gReplacedActNameTable[courseNum] = malloc(sizeof(struct CourseName)); gReplacedActNameTable[courseNum] = calloc(1, sizeof(struct CourseName));
struct CourseName* courseActNames = gReplacedActNameTable[courseNum]; struct CourseName* courseActNames = gReplacedActNameTable[courseNum];
convert_string_sm64_to_ascii(courseBuffer, segmented_to_virtual(courseNameTbl[courseNum])); convert_string_sm64_to_ascii(courseBuffer, segmented_to_virtual(courseNameTbl[courseNum]));
snprintf(courseActNames->name, 50, "%s", courseBuffer); snprintf(courseActNames->name, 50, "%s", courseBuffer);
@ -52,7 +52,7 @@ void smlua_text_utils_init(void) {
snprintf(courseActNames->actName[actNum].orig, 50, "%s", actBuffer); snprintf(courseActNames->actName[actNum].orig, 50, "%s", actBuffer);
courseActNames->actName[actNum].modIndex = -1; courseActNames->actName[actNum].modIndex = -1;
} }
courseActNames->actName[MAX_ACTS_AND_100_COINS].modIndex = -1; courseActNames->actName[MAX_ACTS_AND_100_COINS - 1].modIndex = -1;
} }
} }
} }