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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user