r1225 - trunk/code/botlib
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Sun Dec 2 08:30:14 EST 2007
Author: tma
Date: 2007-12-02 08:30:12 -0500 (Sun, 02 Dec 2007)
New Revision: 1225
Modified:
trunk/code/botlib/l_libvar.c
trunk/code/botlib/l_precomp.c
Log:
* Make some botlib memory allocations /potentially/ safer
Modified: trunk/code/botlib/l_libvar.c
===================================================================
--- trunk/code/botlib/l_libvar.c 2007-12-02 00:48:59 UTC (rev 1224)
+++ trunk/code/botlib/l_libvar.c 2007-12-02 13:30:12 UTC (rev 1225)
@@ -84,9 +84,9 @@
{
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 @@
void LibVarDeAlloc(libvar_t *v)
{
if (v->string) FreeMemory(v->string);
+ FreeMemory(v->name);
FreeMemory(v);
} //end of the function LibVarDeAlloc
//===========================================================================
Modified: trunk/code/botlib/l_precomp.c
===================================================================
--- trunk/code/botlib/l_precomp.c 2007-12-02 00:48:59 UTC (rev 1224)
+++ trunk/code/botlib/l_precomp.c 2007-12-02 13:30:12 UTC (rev 1225)
@@ -653,6 +653,7 @@
PC_FreeToken(t);
} //end for
//free the define
+ FreeMemory(define->name);
FreeMemory(define);
} //end of the function PC_FreeDefine
//============================================================================
@@ -680,9 +681,9 @@
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 @@
#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 *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;
More information about the quake3-commits
mailing list