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

@@ -1767,7 +1767,7 @@ activate_chosen_soundlib(void)
{
int idx = gc.chosen_soundlib;
if (idx < soundlib_nosound || idx >= SIZE(soundlib_choices))
if (!IndexOk(idx, soundlib_choices))
panic("activate_chosen_soundlib: invalid soundlib (%d)", idx);
if (ga.active_soundlib != soundlib_nosound || idx != soundlib_nosound) {
@@ -1784,7 +1784,7 @@ activate_chosen_soundlib(void)
void
assign_soundlib(int idx)
{
if (idx < soundlib_nosound || idx >= SIZE(soundlib_choices))
if (!IndexOk(idx, soundlib_choices))
panic("assign_soundlib: invalid soundlib (%d)", idx);
gc.chosen_soundlib
@@ -1854,7 +1854,7 @@ get_soundlib_name(char *dest, int maxlen)
const char *src;
idx = ga.active_soundlib;
if (idx < soundlib_nosound || idx >= SIZE(soundlib_choices))
if (!IndexOk(idx, soundlib_choices))
panic("get_soundlib_name: invalid active_soundlib (%d)", idx);
src = soundlib_choices[idx].sndprocs->soundname;