mirror of
https://github.com/UberGames/lilium-voyager.git
synced 2024-12-13 21:51:09 +00:00
* Make some botlib memory allocations /potentially/ safer
This commit is contained in:
parent
4f0565a4a7
commit
dfc97a1dfa
2 changed files with 10 additions and 8 deletions
|
@ -84,9 +84,9 @@ libvar_t *LibVarAlloc(char *var_name)
|
|||
{
|
||||
libvar_t *v;
|
||||
|
||||
v = (libvar_t *) GetMemory(sizeof(libvar_t) + strlen(var_name) + 1);
|
||||
v = (libvar_t *) GetMemory(sizeof(libvar_t));
|
||||
Com_Memset(v, 0, sizeof(libvar_t));
|
||||
v->name = (char *) v + sizeof(libvar_t);
|
||||
v->name = (char *) GetMemory(strlen(var_name)+1);
|
||||
strcpy(v->name, var_name);
|
||||
//add the variable in the list
|
||||
v->next = libvarlist;
|
||||
|
@ -102,6 +102,7 @@ libvar_t *LibVarAlloc(char *var_name)
|
|||
void LibVarDeAlloc(libvar_t *v)
|
||||
{
|
||||
if (v->string) FreeMemory(v->string);
|
||||
FreeMemory(v->name);
|
||||
FreeMemory(v);
|
||||
} //end of the function LibVarDeAlloc
|
||||
//===========================================================================
|
||||
|
|
|
@ -653,6 +653,7 @@ void PC_FreeDefine(define_t *define)
|
|||
PC_FreeToken(t);
|
||||
} //end for
|
||||
//free the define
|
||||
FreeMemory(define->name);
|
||||
FreeMemory(define);
|
||||
} //end of the function PC_FreeDefine
|
||||
//============================================================================
|
||||
|
@ -680,9 +681,9 @@ void PC_AddBuiltinDefines(source_t *source)
|
|||
|
||||
for (i = 0; builtin[i].string; i++)
|
||||
{
|
||||
define = (define_t *) GetMemory(sizeof(define_t) + strlen(builtin[i].string) + 1);
|
||||
define = (define_t *) GetMemory(sizeof(define_t));
|
||||
Com_Memset(define, 0, sizeof(define_t));
|
||||
define->name = (char *) define + sizeof(define_t);
|
||||
define->name = (char *) GetMemory(strlen(builtin[i].string) + 1);
|
||||
strcpy(define->name, builtin[i].string);
|
||||
define->flags |= DEFINE_FIXED;
|
||||
define->builtin = builtin[i].builtin;
|
||||
|
@ -1216,9 +1217,9 @@ int PC_Directive_define(source_t *source)
|
|||
#endif //DEFINEHASHING
|
||||
} //end if
|
||||
//allocate define
|
||||
define = (define_t *) GetMemory(sizeof(define_t) + strlen(token.string) + 1);
|
||||
define = (define_t *) GetMemory(sizeof(define_t));
|
||||
Com_Memset(define, 0, sizeof(define_t));
|
||||
define->name = (char *) define + sizeof(define_t);
|
||||
define->name = (char *) GetMemory(strlen(token.string) + 1);
|
||||
strcpy(define->name, token.string);
|
||||
//add the define to the source
|
||||
#if DEFINEHASHING
|
||||
|
@ -1452,9 +1453,9 @@ define_t *PC_CopyDefine(source_t *source, define_t *define)
|
|||
define_t *newdefine;
|
||||
token_t *token, *newtoken, *lasttoken;
|
||||
|
||||
newdefine = (define_t *) GetMemory(sizeof(define_t) + strlen(define->name) + 1);
|
||||
newdefine = (define_t *) GetMemory(sizeof(define_t));
|
||||
//copy the define name
|
||||
newdefine->name = (char *) newdefine + sizeof(define_t);
|
||||
newdefine->name = (char *) GetMemory(strlen(define->name) + 1);
|
||||
strcpy(newdefine->name, define->name);
|
||||
newdefine->flags = define->flags;
|
||||
newdefine->builtin = define->builtin;
|
||||
|
|
Loading…
Reference in a new issue