From: bones_was_here Date: Thu, 21 Dec 2023 11:06:36 +0000 (+1000) Subject: cvar: use unsigned for flags and hashindex X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=fd87ca0bf3aa1d7bbc9f90302053d26b66350697;p=xonotic%2Fdarkplaces.git cvar: use unsigned for flags and hashindex Signed is too error-prone with bitwise operations. The common pattern of passing ~0 (all bits set) resulted in neededflags=-1 in a backtrace on x86_64. See also b8692b8cd73685794b59b0522e8caa4b9d9a2dac Signed-off-by: bones_was_here --- diff --git a/cvar.c b/cvar.c index 10eda39d..3008bb20 100644 --- a/cvar.c +++ b/cvar.c @@ -33,9 +33,9 @@ cvar_state_t cvars_null; Cvar_FindVar ============ */ -cvar_t *Cvar_FindVar(cvar_state_t *cvars, const char *var_name, int neededflags) +cvar_t *Cvar_FindVar(cvar_state_t *cvars, const char *var_name, unsigned neededflags) { - int hashindex; + unsigned hashindex; cvar_hash_t *hash; // use hash lookup to minimize search time @@ -50,7 +50,7 @@ cvar_t *Cvar_FindVar(cvar_state_t *cvars, const char *var_name, int neededflags) return NULL; } -cvar_t *Cvar_FindVarAfter(cvar_state_t *cvars, const char *prev_var_name, int neededflags) +cvar_t *Cvar_FindVarAfter(cvar_state_t *cvars, const char *prev_var_name, unsigned neededflags) { cvar_t *var; @@ -78,9 +78,9 @@ cvar_t *Cvar_FindVarAfter(cvar_state_t *cvars, const char *prev_var_name, int ne * Returns a pointer to the pointer stored in hashtable[] (or the one it links to) * because we'll need to update that when deleting a cvar as other cvar(s) may share its hashindex. */ -static cvar_hash_t **Cvar_FindVarLink(cvar_state_t *cvars, const char *var_name, cvar_t **parent, cvar_t ***link, cvar_t **prev_alpha, int neededflags) +static cvar_hash_t **Cvar_FindVarLink(cvar_state_t *cvars, const char *var_name, cvar_t **parent, cvar_t ***link, cvar_t **prev_alpha, unsigned neededflags) { - int hashindex; + unsigned hashindex; cvar_t *cvar; cvar_hash_t **hashlinkptr; @@ -119,7 +119,7 @@ match: Cvar_VariableValue ============ */ -float Cvar_VariableValueOr(cvar_state_t *cvars, const char *var_name, float def, int neededflags) +float Cvar_VariableValueOr(cvar_state_t *cvars, const char *var_name, float def, unsigned neededflags) { cvar_t *var; @@ -129,7 +129,7 @@ float Cvar_VariableValueOr(cvar_state_t *cvars, const char *var_name, float def, return atof (var->string); } -float Cvar_VariableValue(cvar_state_t *cvars, const char *var_name, int neededflags) +float Cvar_VariableValue(cvar_state_t *cvars, const char *var_name, unsigned neededflags) { return Cvar_VariableValueOr(cvars, var_name, 0, neededflags); } @@ -139,7 +139,7 @@ float Cvar_VariableValue(cvar_state_t *cvars, const char *var_name, int neededfl Cvar_VariableString ============ */ -const char *Cvar_VariableStringOr(cvar_state_t *cvars, const char *var_name, const char *def, int neededflags) +const char *Cvar_VariableStringOr(cvar_state_t *cvars, const char *var_name, const char *def, unsigned neededflags) { cvar_t *var; @@ -149,7 +149,7 @@ const char *Cvar_VariableStringOr(cvar_state_t *cvars, const char *var_name, con return var->string; } -const char *Cvar_VariableString(cvar_state_t *cvars, const char *var_name, int neededflags) +const char *Cvar_VariableString(cvar_state_t *cvars, const char *var_name, unsigned neededflags) { return Cvar_VariableStringOr(cvars, var_name, cvar_null_string, neededflags); } @@ -159,7 +159,7 @@ const char *Cvar_VariableString(cvar_state_t *cvars, const char *var_name, int n Cvar_VariableDefString ============ */ -const char *Cvar_VariableDefString(cvar_state_t *cvars, const char *var_name, int neededflags) +const char *Cvar_VariableDefString(cvar_state_t *cvars, const char *var_name, unsigned neededflags) { cvar_t *var; @@ -174,7 +174,7 @@ const char *Cvar_VariableDefString(cvar_state_t *cvars, const char *var_name, in Cvar_VariableDescription ============ */ -const char *Cvar_VariableDescription(cvar_state_t *cvars, const char *var_name, int neededflags) +const char *Cvar_VariableDescription(cvar_state_t *cvars, const char *var_name, unsigned neededflags) { cvar_t *var; @@ -190,7 +190,7 @@ const char *Cvar_VariableDescription(cvar_state_t *cvars, const char *var_name, Cvar_CompleteVariable ============ */ -const char *Cvar_CompleteVariable(cvar_state_t *cvars, const char *partial, int neededflags) +const char *Cvar_CompleteVariable(cvar_state_t *cvars, const char *partial, unsigned neededflags) { cvar_t *cvar; size_t len; @@ -217,7 +217,7 @@ const char *Cvar_CompleteVariable(cvar_state_t *cvars, const char *partial, int Thanks to Fett erich@heintz.com */ -int Cvar_CompleteCountPossible(cvar_state_t *cvars, const char *partial, int neededflags) +int Cvar_CompleteCountPossible(cvar_state_t *cvars, const char *partial, unsigned neededflags) { cvar_t *cvar; size_t len; @@ -250,7 +250,7 @@ int Cvar_CompleteCountPossible(cvar_state_t *cvars, const char *partial, int nee Thanks to taniwha */ -const char **Cvar_CompleteBuildList(cvar_state_t *cvars, const char *partial, int neededflags) +const char **Cvar_CompleteBuildList(cvar_state_t *cvars, const char *partial, unsigned neededflags) { const cvar_t *cvar; size_t len = 0; @@ -288,7 +288,7 @@ void Cvar_PrintHelp(cvar_t *cvar, const char *name, qbool full) } // written by LadyHavoc -void Cvar_CompleteCvarPrint(cvar_state_t *cvars, const char *partial, int neededflags) +void Cvar_CompleteCvarPrint(cvar_state_t *cvars, const char *partial, unsigned neededflags) { cvar_t *cvar; size_t len = strlen(partial); @@ -516,7 +516,7 @@ void Cvar_RegisterVirtual(cvar_t *variable, const char *name ) { cvar_state_t *cvars = &cvars_all; cvar_hash_t *hash; - int hashindex; + unsigned hashindex; if (!(variable->flags & cmd_local->cvars_flagsmask)) { @@ -570,7 +570,7 @@ static void Cvar_Link(cvar_t *variable, cvar_state_t *cvars) { cvar_t *current, *next; cvar_hash_t *hash; - int hashindex; + unsigned hashindex; /* * Link the variable in * alphanumerical order @@ -854,7 +854,7 @@ void Cvar_SaveInitState(cvar_state_t *cvars) void Cvar_RestoreInitState(cvar_state_t *cvars) { - int hashindex; + unsigned hashindex; cvar_t *c, **cp; cvar_t *c2, **cp2; for (cp = &cvars->vars;(c = *cp);) diff --git a/cvar.h b/cvar.h index 92ea81cd..709bc6aa 100644 --- a/cvar.h +++ b/cvar.h @@ -64,7 +64,7 @@ struct qfile_s; typedef struct cvar_s { - int flags; + unsigned flags; const char *name; @@ -126,31 +126,31 @@ void Cvar_SetValue (cvar_state_t *cvars, const char *var_name, float value); void Cvar_SetQuick (cvar_t *var, const char *value); void Cvar_SetValueQuick (cvar_t *var, float value); -float Cvar_VariableValueOr (cvar_state_t *cvars, const char *var_name, float def, int neededflags); +float Cvar_VariableValueOr (cvar_state_t *cvars, const char *var_name, float def, unsigned neededflags); // returns def if not defined -float Cvar_VariableValue (cvar_state_t *cvars, const char *var_name, int neededflags); +float Cvar_VariableValue (cvar_state_t *cvars, const char *var_name, unsigned neededflags); // returns 0 if not defined or non numeric -const char *Cvar_VariableStringOr (cvar_state_t *cvars, const char *var_name, const char *def, int neededflags); +const char *Cvar_VariableStringOr (cvar_state_t *cvars, const char *var_name, const char *def, unsigned neededflags); // returns def if not defined -const char *Cvar_VariableString (cvar_state_t *cvars, const char *var_name, int neededflags); +const char *Cvar_VariableString (cvar_state_t *cvars, const char *var_name, unsigned neededflags); // returns an empty string if not defined -const char *Cvar_VariableDefString (cvar_state_t *cvars, const char *var_name, int neededflags); +const char *Cvar_VariableDefString (cvar_state_t *cvars, const char *var_name, unsigned neededflags); // returns an empty string if not defined -const char *Cvar_VariableDescription (cvar_state_t *cvars, const char *var_name, int neededflags); +const char *Cvar_VariableDescription (cvar_state_t *cvars, const char *var_name, unsigned neededflags); // returns an empty string if not defined -const char *Cvar_CompleteVariable (cvar_state_t *cvars, const char *partial, int neededflags); +const char *Cvar_CompleteVariable (cvar_state_t *cvars, const char *partial, unsigned neededflags); // attempts to match a partial variable name for command line completion // returns NULL if nothing fits void Cvar_PrintHelp(cvar_t *cvar, const char *name, qbool full); -void Cvar_CompleteCvarPrint (cvar_state_t *cvars, const char *partial, int neededflags); +void Cvar_CompleteCvarPrint (cvar_state_t *cvars, const char *partial, unsigned neededflags); qbool Cvar_Command (struct cmd_state_s *cmd); // called by Cmd_ExecuteString when Cmd_Argv(cmd, 0) doesn't match a known @@ -170,11 +170,11 @@ void Cvar_WriteVariables (cvar_state_t *cvars, struct qfile_s *f); // Writes lines containing "set variable value" for all variables // with the archive flag set to true. -cvar_t *Cvar_FindVar(cvar_state_t *cvars, const char *var_name, int neededflags); -cvar_t *Cvar_FindVarAfter(cvar_state_t *cvars, const char *prev_var_name, int neededflags); +cvar_t *Cvar_FindVar(cvar_state_t *cvars, const char *var_name, unsigned neededflags); +cvar_t *Cvar_FindVarAfter(cvar_state_t *cvars, const char *prev_var_name, unsigned neededflags); -int Cvar_CompleteCountPossible(cvar_state_t *cvars, const char *partial, int neededflags); -const char **Cvar_CompleteBuildList(cvar_state_t *cvars, const char *partial, int neededflags); +int Cvar_CompleteCountPossible(cvar_state_t *cvars, const char *partial, unsigned neededflags); +const char **Cvar_CompleteBuildList(cvar_state_t *cvars, const char *partial, unsigned neededflags); // Added by EvilTypeGuy - functions for tab completion system // Thanks to Fett erich@heintz.com // Thanks to taniwha