Skip to content

Commit 1fbe5cc

Browse files
committed
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>
1 parent 8bfd83c commit 1fbe5cc

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

games/NXDoom/src/m_config.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,16 +1982,14 @@ static void save_default_collection(default_collection_t *collection)
19821982
*
19831983
****************************************************************************/
19841984

1985-
static int parse_int_parameter(const char *strparm)
1985+
static int parse_int_parameter(const char *strparm, int *param)
19861986
{
1987-
int param;
1988-
19891987
if (strparm[0] == '0' && strparm[1] == 'x')
1990-
sscanf(strparm + 2, "%x", (unsigned int *)&param);
1991-
else
1992-
sscanf(strparm, "%i", &param);
1988+
{
1989+
return sscanf(strparm + 2, "%x", (unsigned int *)param) == 1;
1990+
}
19931991

1994-
return param;
1992+
return sscanf(strparm, "%i", param) == 1;
19951993
}
19961994

19971995
static void set_variable(default_t *def, const char *value)
@@ -2008,7 +2006,11 @@ static void set_variable(default_t *def, const char *value)
20082006

20092007
case DEFAULT_INT:
20102008
case DEFAULT_INT_HEX:
2011-
*def->location.i = parse_int_parameter(value);
2009+
if (parse_int_parameter(value, &intparm))
2010+
{
2011+
*def->location.i = intparm;
2012+
}
2013+
20122014
break;
20132015

20142016
case DEFAULT_KEY:
@@ -2017,7 +2019,11 @@ static void set_variable(default_t *def, const char *value)
20172019
* file (save the old value in untranslated)
20182020
*/
20192021

2020-
intparm = parse_int_parameter(value);
2022+
if (!parse_int_parameter(value, &intparm))
2023+
{
2024+
break;
2025+
}
2026+
20212027
def->untranslated = intparm;
20222028
if (intparm >= 0 && intparm < 128)
20232029
{

0 commit comments

Comments
 (0)