From 36910c88033bcc4b25df5c64ed066c633dc4eac2 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Fri, 27 Jun 2025 22:45:11 +0100 Subject: 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] --- src/build/mkgamedata.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/build') 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) { -- cgit v1.2.3-54-g00ecf