From 65938da5ae036de3ea80c845beb4a99accc49c78 Mon Sep 17 00:00:00 2001 From: Thilo Schulz Date: Thu, 1 May 2008 11:29:49 +0000 Subject: [PATCH] - variables with CVAR_ROM set get now overwritten by Cvar_Get() if the cvar exists already but was created by the user. - Fix null pointer crash in Cvar_Print_f(), thanks to humancontroller for reporting. --- code/qcommon/cvar.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/code/qcommon/cvar.c b/code/qcommon/cvar.c index cd0e8aaa..9dfff2e1 100644 --- a/code/qcommon/cvar.c +++ b/code/qcommon/cvar.c @@ -239,6 +239,16 @@ cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) { // we don't have a reset string yet Z_Free( var->resetString ); var->resetString = CopyString( var_value ); + + // if there is no reset string yet this means the variable was set by the user, + // so force it to value given by the engine. + if(var->flags & CVAR_ROM) + { + if(var->latchedString) + Z_Free(var->latchedString); + + var->latchedString = CopyString(var_value); + } } else if ( var_value[0] && strcmp( var->resetString, var_value ) ) { Com_DPrintf( "Warning: cvar \"%s\" given initial values: \"%s\" and \"%s\"\n", var_name, var->resetString, var_value ); @@ -253,13 +263,6 @@ cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) { Z_Free( s ); } -// use a CVAR_SET for rom sets, get won't override -#if 0 - // CVAR_ROM always overrides - if ( flags & CVAR_ROM ) { - Cvar_Set2( var_name, var_value, qtrue ); - } -#endif return var; } @@ -553,8 +556,25 @@ Prints the contents of a cvar (preferred over Cvar_Command where cvar names and commands conflict) ============ */ -void Cvar_Print_f( void ) { - Cvar_Print (Cvar_FindVar (Cmd_Argv(1)) ); +void Cvar_Print_f(void) +{ + char *name; + cvar_t *cv; + + if(Cmd_Argc() != 2) + { + Com_Printf ("usage: print \n"); + return; + } + + name = Cmd_Argv(1); + + cv = Cvar_FindVar(name); + + if(cv) + Cvar_Print(cv); + else + Com_Printf ("Cvar %s does not exist.\n", name); } /* @@ -599,8 +619,7 @@ void Cvar_Set_f( void ) { return; } if ( c == 2 ) { - v = Cvar_FindVar (Cmd_Argv(1)); - Cvar_Print( v ); + Cvar_Print_f(); return; }