- variable->aliases = (char **)Mem_Realloc(zonemempool, variable->aliases, sizeof(char *) * (variable->aliasindex + 1));
- // Add to it
- variable->aliases[variable->aliasindex] = (char *)Z_Malloc(strlen(alias) + 1);
- memcpy(variable->aliases[variable->aliasindex], alias, strlen(alias) + 1);
- variable->aliasindex++;
+ if(!*name)
+ {
+ Con_Printf("Cvar_RegisterVirtual: invalid virtual cvar name\n");
+ return;
+ }
+
+ // check for overlap with a command
+ if (Cmd_Exists(cmd_local, name))
+ {
+ Con_Printf("Cvar_RegisterVirtual: %s is a command\n", name);
+ return;
+ }
+
+ if(Cvar_FindVar(&cvars_all, name, 0))
+ {
+ Con_Printf("Cvar_RegisterVirtual: %s is a cvar\n", name);
+ return;
+ }
+
+ // Resize the variable->aliases list to have room for another entry and a null terminator.
+ // This zero-pads when resizing, so we don't need to write the NULL terminator manually here.
+ // Also if aliases is NULL this allocates fresh for the correct size, so it's fine to just do this.
+ variable->aliases = (char **)Z_Realloc(variable->aliases, sizeof(char *) * (variable->aliases_size + 2));
+ // Add the new alias, and increment the number of aliases in the list
+ variable->aliases[variable->aliases_size++] = (char *)Z_strdup(name);