mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
games/NXDoom: Preserve defaults for invalid integer settings.
Check integer conversions before updating bound configuration values. This keeps compiled defaults intact for malformed non-numeric values instead of propagating an uninitialized result from sscanf(). Assisted-by: Codex:gpt-5 Signed-off-by: aviralgarg05 <gargaviral99@gmail.com>
This commit is contained in:
parent
8bfd83c401
commit
1fbe5cc678
1 changed files with 15 additions and 9 deletions
|
|
@ -1982,16 +1982,14 @@ static void save_default_collection(default_collection_t *collection)
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int parse_int_parameter(const char *strparm)
|
||||
static int parse_int_parameter(const char *strparm, int *param)
|
||||
{
|
||||
int param;
|
||||
|
||||
if (strparm[0] == '0' && strparm[1] == 'x')
|
||||
sscanf(strparm + 2, "%x", (unsigned int *)¶m);
|
||||
else
|
||||
sscanf(strparm, "%i", ¶m);
|
||||
{
|
||||
return sscanf(strparm + 2, "%x", (unsigned int *)param) == 1;
|
||||
}
|
||||
|
||||
return param;
|
||||
return sscanf(strparm, "%i", param) == 1;
|
||||
}
|
||||
|
||||
static void set_variable(default_t *def, const char *value)
|
||||
|
|
@ -2008,7 +2006,11 @@ static void set_variable(default_t *def, const char *value)
|
|||
|
||||
case DEFAULT_INT:
|
||||
case DEFAULT_INT_HEX:
|
||||
*def->location.i = parse_int_parameter(value);
|
||||
if (parse_int_parameter(value, &intparm))
|
||||
{
|
||||
*def->location.i = intparm;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case DEFAULT_KEY:
|
||||
|
|
@ -2017,7 +2019,11 @@ static void set_variable(default_t *def, const char *value)
|
|||
* file (save the old value in untranslated)
|
||||
*/
|
||||
|
||||
intparm = parse_int_parameter(value);
|
||||
if (!parse_int_parameter(value, &intparm))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
def->untranslated = intparm;
|
||||
if (intparm >= 0 && intparm < 128)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue