r1334 - trunk/code/qcommon

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Thu May 1 07:29:49 EDT 2008


Author: thilo
Date: 2008-05-01 07:29:49 -0400 (Thu, 01 May 2008)
New Revision: 1334

Modified:
   trunk/code/qcommon/cvar.c
Log:
- 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.


Modified: trunk/code/qcommon/cvar.c
===================================================================
--- trunk/code/qcommon/cvar.c	2008-04-29 22:49:37 UTC (rev 1333)
+++ trunk/code/qcommon/cvar.c	2008-05-01 11:29:49 UTC (rev 1334)
@@ -239,6 +239,16 @@
 			// 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 @@
 			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 @@
 (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 <variable>\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 @@
 		return;
 	}
 	if ( c == 2 ) {
-		v = Cvar_FindVar (Cmd_Argv(1));
-		Cvar_Print( v );
+		Cvar_Print_f();
 		return;
 	}
 




More information about the quake3-commits mailing list