add a pair of shorthand macros to validate an index into an array

Two variations:

IndexOk(idx, array)       validate that idx is a valid index into the array

IndexOkT(idx, array)      validate that idx is a valid index into the
                          array, excluding the final Terminator element
This commit is contained in:
nhmall
2023-12-23 13:46:54 -05:00
parent 415f8c559b
commit e9e05db113
7 changed files with 20 additions and 11 deletions

View File

@@ -2591,7 +2591,7 @@ hliquid(
if (liquidpref && *liquidpref)
++count;
indx = rn2_on_display_rng(count);
if (indx < SIZE(hliquids))
if (IndexOk(indx, hliquids))
return hliquids[indx];
}
return liquidpref;
@@ -2742,7 +2742,7 @@ lookup_novel(const char *lookname, int *idx)
}
}
/* name not found; if novelidx is already set, override the name */
if (idx && *idx >= 0 && *idx < SIZE(sir_Terry_novels))
if (idx && IndexOk(*idx, sir_Terry_novels))
return sir_Terry_novels[*idx];
return (const char *) 0;