]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cvar.c
got rid of buildnumber.c and buildnum program, now uses builddate.c (touched each...
[xonotic/darkplaces.git] / cvar.c
diff --git a/cvar.c b/cvar.c
index d38c5ba9eeda565bf22dc6b3c351e0521855c5d5..25ad1421f93ea6526602fec2aa57f14b50d398dd 100644 (file)
--- a/cvar.c
+++ b/cvar.c
@@ -144,7 +144,7 @@ Cvar_CompleteBuildList (char *partial)
        char    **buf;
 
        len = strlen(partial);
-       buf = qmalloc(sizeofbuf + sizeof (char *));
+       buf = Mem_Alloc(tempmempool, sizeofbuf + sizeof (char *));
        // Loop through the alias list and print all matches
        for (cvar = cvar_vars; cvar; cvar = cvar->next)
                if (!strncasecmp(partial, cvar->name, len))
@@ -172,12 +172,20 @@ void Cvar_Set (char *var_name, char *value)
        }
 
        changed = strcmp(var->string, value);
+       // LordHavoc: don't reallocate when there is no change
+       if (!changed)
+               return;
 
-       Z_Free (var->string);   // free the old value string
+       // LordHavoc: don't reallocate when the buffer is the same size
+       if (!var->string || strlen(var->string) != strlen(value))
+       {
+               Z_Free (var->string);   // free the old value string
 
-       var->string = Z_Malloc (strlen(value)+1);
+               var->string = Z_Malloc (strlen(value)+1);
+       }
        strcpy (var->string, value);
        var->value = atof (var->string);
+       var->integer = (int) var->value;
        if ((var->flags & CVAR_NOTIFY) && changed)
        {
                if (sv.active)
@@ -229,6 +237,7 @@ void Cvar_RegisterVariable (cvar_t *variable)
        variable->string = Z_Malloc (strlen(variable->string)+1);
        strcpy (variable->string, oldstr);
        variable->value = atof (variable->string);
+       variable->integer = (int) variable->value;
 
 // link the variable in
        variable->next = cvar_vars;