From 0cde312437aa04ff886cc19082e53f1fd2db57b7 Mon Sep 17 00:00:00 2001 From: nhmall Date: Fri, 22 Dec 2023 17:41:06 -0500 Subject: [PATCH] static analyzer bit in options.c src/options.c(711): warning: Reading invalid data from 'roleoptvals[roleoptindx]'. Validate the roleoptvals[][] array indexes to appease the static analyzer. --- src/options.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/options.c b/src/options.c index fabb8a96c..6f2f8f9b6 100644 --- a/src/options.c +++ b/src/options.c @@ -125,8 +125,9 @@ static char empty_optstr[] = { '\0' }; static boolean duplicate, using_alias; static boolean give_opt_msg = TRUE; +enum roleopts { roleopt_role, roleopt_race, roleopt_gend, roleopt_algn, MAX_ROLEOPT }; static boolean opt_set_in_config[OPTCOUNT]; -static char *roleoptvals[4][num_opt_phases]; /* 4: role,race,gend,algn */ +static char *roleoptvals[MAX_ROLEOPT][num_opt_phases]; /* 4: role,race,gend,algn */ static NEARDATA const char *OptS_type[OptS_Advanced+1] = { "General", "Behavior", "Map", "Status", "Advanced" @@ -708,7 +709,11 @@ getoptstr(int optidx, int ophase) break; } } - return roleoptvals[roleoptindx][ophase]; + if ((roleoptindx >= 0 && roleoptindx < MAX_ROLEOPT + && ophase >= 0 && ophase < num_opt_phases)) + return roleoptvals[roleoptindx][ophase]; + panic("bad index roleoptvals[%d][%d]", roleoptindx, ophase); + /*NOTREACHED*/ } /* to track some unparsed option settings in case #saveoptions needs them */