aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-06-27 22:45:11 +0100
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-06-27 22:52:10 +0100
commit36910c88033bcc4b25df5c64ed066c633dc4eac2 (patch)
treeab3163814747938b7bcbf39dc3aef8a2f2f9c359 /src
parenta9f44f3a6cccdf147376f8bf010a85b334ed4c72 (diff)
downloadsst-36910c88033bcc4b25df5c64ed066c633dc4eac2.tar.gz
sst-36910c88033bcc4b25df5c64ed066c633dc4eac2.zip
Fix indexing edge case in mkgamedata
This took longer to debug than one might like to admit. In some very specific cases, the loop condition would fail before the return condition, causing the rest of the logic to proceed with out-of-bounds accesses to indents and exprs (which are zero-initialised), in turn leading to garbage getting dumped into the generated header. The garbage in question would be line 0, and [argv[0]
Diffstat (limited to 'src')
-rw-r--r--src/build/mkgamedata.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/build/mkgamedata.c b/src/build/mkgamedata.c
index f187028..d3b9c9c 100644
--- a/src/build/mkgamedata.c
+++ b/src/build/mkgamedata.c
@@ -169,7 +169,9 @@ static inline void knowngames(FILE *out) {
while (exprs[i]) { // if there's a default value, we don't need this
// skip to next unindented thing, return if there isn't one with at
// least one indented thing under it.
- for (++i; indents[i] != 0; ++i) if (i == nents - 1) return;
+ do {
+ if (++i == nents - 1) return;
+ } while (indents[i] != 0);
}
F( "#line %d \"%" fS "\"", srclines[i], srcnames[srcfiles[i]])
if_cold (fprintf(out, "#define _GAMES_WITH_%s (", sbase + tags[i]) < 0) {