From ecd675926a2055e57aa78cf9a21fde155750abb9 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 26 Nov 2019 02:48:16 +0300 Subject: [PATCH] engine: cvar: add null checks as these functions are passed to user's DLL --- engine/common/cvar.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/engine/common/cvar.c b/engine/common/cvar.c index 6f507ba9..27477362 100644 --- a/engine/common/cvar.c +++ b/engine/common/cvar.c @@ -590,7 +590,16 @@ Cvar_Set */ void Cvar_Set( const char *var_name, const char *value ) { - convar_t *var = Cvar_FindVar( var_name ); + convar_t *var; + + if( !var_name ) + { + // there is an error in C code if this happens + Con_Printf( "Cvar_Set: passed NULL variable name\n", var_name ); + return; + } + + var = Cvar_FindVar( var_name ); if( !var ) { @@ -637,6 +646,13 @@ float Cvar_VariableValue( const char *var_name ) { convar_t *var; + if( !var_name ) + { + // there is an error in C code if this happens + Con_Printf( "Cvar_VariableValue: passed NULL variable name\n", var_name ); + return 0.0f; + } + var = Cvar_FindVar( var_name ); if( !var ) return 0.0f; @@ -667,6 +683,13 @@ const char *Cvar_VariableString( const char *var_name ) { convar_t *var; + if( !var_name ) + { + // there is an error in C code if this happens + Con_Printf( "Cvar_VariableString: passed NULL variable name\n", var_name ); + return ""; + } + var = Cvar_FindVar( var_name ); if( !var ) return "";