functions "luaI_free" and "luaI_realloc" (or macro "growvector") may be
called with NULL.
This commit is contained in:
14
fallback.c
14
fallback.c
@@ -3,7 +3,7 @@
|
|||||||
** TecCGraf - PUC-Rio
|
** TecCGraf - PUC-Rio
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_fallback="$Id: fallback.c,v 1.18 1996/01/30 15:25:23 roberto Exp roberto $";
|
char *rcs_fallback="$Id: fallback.c,v 1.19 1996/02/08 19:08:34 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -132,16 +132,8 @@ int luaI_lock (Object *object)
|
|||||||
}
|
}
|
||||||
/* no more empty spaces */
|
/* no more empty spaces */
|
||||||
oldSize = lockSize;
|
oldSize = lockSize;
|
||||||
if (lockArray == NULL)
|
lockSize = (lockSize == 0) ? 10 : 3*lockSize/2 + 5;
|
||||||
{
|
lockArray = growvector(lockArray, lockSize, Object);
|
||||||
lockSize = 10;
|
|
||||||
lockArray = newvector(lockSize, Object);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lockSize = 3*oldSize/2 + 5;
|
|
||||||
lockArray = growvector(lockArray, lockSize, Object);
|
|
||||||
}
|
|
||||||
for (i=oldSize; i<lockSize; i++)
|
for (i=oldSize; i<lockSize; i++)
|
||||||
tag(&lockArray[i]) = LUA_T_NIL;
|
tag(&lockArray[i]) = LUA_T_NIL;
|
||||||
lockArray[oldSize] = *object;
|
lockArray[oldSize] = *object;
|
||||||
|
|||||||
17
func.c
17
func.c
@@ -42,8 +42,7 @@ void luaI_insertfunction (TFunc *f)
|
|||||||
static void freefunc (TFunc *f)
|
static void freefunc (TFunc *f)
|
||||||
{
|
{
|
||||||
luaI_free (f->code);
|
luaI_free (f->code);
|
||||||
if (f->locvars)
|
luaI_free (f->locvars);
|
||||||
luaI_free (f->locvars);
|
|
||||||
luaI_free (f);
|
luaI_free (f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,16 +99,10 @@ void lua_funcinfo (lua_Object func, char **filename, int *linedefined)
|
|||||||
void luaI_registerlocalvar (TaggedString *varname, int line)
|
void luaI_registerlocalvar (TaggedString *varname, int line)
|
||||||
{
|
{
|
||||||
if (numcurrvars >= maxcurrvars)
|
if (numcurrvars >= maxcurrvars)
|
||||||
if (currvars == NULL)
|
{
|
||||||
{
|
maxcurrvars = (maxcurrvars == 0) ? LOCALVARINITSIZE : maxcurrvars*2;
|
||||||
maxcurrvars = LOCALVARINITSIZE;
|
currvars = growvector(currvars, maxcurrvars, LocVar);
|
||||||
currvars = newvector (maxcurrvars, LocVar);
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
maxcurrvars *= 2;
|
|
||||||
currvars = growvector (currvars, maxcurrvars, LocVar);
|
|
||||||
}
|
|
||||||
currvars[numcurrvars].varname = varname;
|
currvars[numcurrvars].varname = varname;
|
||||||
currvars[numcurrvars].line = line;
|
currvars[numcurrvars].line = line;
|
||||||
numcurrvars++;
|
numcurrvars++;
|
||||||
|
|||||||
19
luamem.c
19
luamem.c
@@ -3,7 +3,7 @@
|
|||||||
** TecCGraf - PUC-Rio
|
** TecCGraf - PUC-Rio
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_mem = "$Id: mem.c,v 1.6 1996/01/22 14:15:13 roberto Exp roberto $";
|
char *rcs_mem = "$Id: mem.c,v 1.7 1996/02/04 16:59:12 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -27,8 +27,11 @@ static void mem_error (void)
|
|||||||
|
|
||||||
void luaI_free (void *block)
|
void luaI_free (void *block)
|
||||||
{
|
{
|
||||||
*((int *)block) = -1; /* to catch errors */
|
if (block)
|
||||||
free(block);
|
{
|
||||||
|
*((int *)block) = -1; /* to catch errors */
|
||||||
|
free(block);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -43,16 +46,10 @@ void *luaI_malloc (unsigned long size)
|
|||||||
|
|
||||||
void *luaI_realloc (void *oldblock, unsigned long size)
|
void *luaI_realloc (void *oldblock, unsigned long size)
|
||||||
{
|
{
|
||||||
void *block = realloc(oldblock, (size_t)size);
|
void *block = oldblock ? realloc(oldblock, (size_t)size) :
|
||||||
|
malloc((size_t)size);
|
||||||
if (block == NULL)
|
if (block == NULL)
|
||||||
mem_error();
|
mem_error();
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *luaI_strdup (char *str)
|
|
||||||
{
|
|
||||||
char *newstr = luaI_malloc(strlen(str)+1);
|
|
||||||
strcpy(newstr, str);
|
|
||||||
return newstr;
|
|
||||||
}
|
|
||||||
|
|||||||
4
luamem.h
4
luamem.h
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
** mem.c
|
** mem.c
|
||||||
** memory manager for lua
|
** memory manager for lua
|
||||||
** $Id: mem.h,v 1.1 1994/11/16 17:38:08 roberto Stab roberto $
|
** $Id: mem.h,v 1.2 1995/01/13 22:11:12 roberto Exp roberto $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef mem_h
|
#ifndef mem_h
|
||||||
@@ -15,8 +15,6 @@ void luaI_free (void *block);
|
|||||||
void *luaI_malloc (unsigned long size);
|
void *luaI_malloc (unsigned long size);
|
||||||
void *luaI_realloc (void *oldblock, unsigned long size);
|
void *luaI_realloc (void *oldblock, unsigned long size);
|
||||||
|
|
||||||
char *luaI_strdup (char *str);
|
|
||||||
|
|
||||||
#define new(s) ((s *)luaI_malloc(sizeof(s)))
|
#define new(s) ((s *)luaI_malloc(sizeof(s)))
|
||||||
#define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s)))
|
#define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s)))
|
||||||
#define growvector(old,n,s) ((s *)luaI_realloc(old,(n)*sizeof(s)))
|
#define growvector(old,n,s) ((s *)luaI_realloc(old,(n)*sizeof(s)))
|
||||||
|
|||||||
8
opcode.c
8
opcode.c
@@ -3,7 +3,7 @@
|
|||||||
** TecCGraf - PUC-Rio
|
** TecCGraf - PUC-Rio
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_opcode="$Id: opcode.c,v 3.56 1996/02/08 17:03:20 roberto Exp roberto $";
|
char *rcs_opcode="$Id: opcode.c,v 3.57 1996/02/12 18:32:40 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -135,8 +135,7 @@ static char *lua_strconc (char *l, char *r)
|
|||||||
if (n > buffer_size)
|
if (n > buffer_size)
|
||||||
{
|
{
|
||||||
buffer_size = n;
|
buffer_size = n;
|
||||||
if (buffer != NULL)
|
luaI_free(buffer);
|
||||||
luaI_free(buffer);
|
|
||||||
buffer = newvector(buffer_size, char);
|
buffer = newvector(buffer_size, char);
|
||||||
}
|
}
|
||||||
strcpy(buffer,l);
|
strcpy(buffer,l);
|
||||||
@@ -525,8 +524,7 @@ static int do_protectedmain (void)
|
|||||||
adjustC(0); /* erase extra slot */
|
adjustC(0); /* erase extra slot */
|
||||||
}
|
}
|
||||||
errorJmp = oldErr;
|
errorJmp = oldErr;
|
||||||
if (tf.code)
|
luaI_free(tf.code);
|
||||||
luaI_free(tf.code);
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
28
tree.c
28
tree.c
@@ -3,7 +3,7 @@
|
|||||||
** TecCGraf - PUC-Rio
|
** TecCGraf - PUC-Rio
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_tree="$Id: tree.c,v 1.17 1996/02/14 13:35:51 roberto Exp roberto $";
|
char *rcs_tree="$Id: tree.c,v 1.18 1996/02/14 19:11:09 roberto Exp roberto $";
|
||||||
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -55,20 +55,18 @@ static void grow (stringtable *tb)
|
|||||||
int i;
|
int i;
|
||||||
for (i=0; i<newsize; i++)
|
for (i=0; i<newsize; i++)
|
||||||
newhash[i] = NULL;
|
newhash[i] = NULL;
|
||||||
if (tb->size > 0)
|
/* rehash */
|
||||||
{ /* rehash */
|
tb->nuse = 0;
|
||||||
tb->nuse = 0;
|
for (i=0; i<tb->size; i++)
|
||||||
for (i=0; i<tb->size; i++)
|
if (tb->hash[i] != NULL && tb->hash[i] != &EMPTY)
|
||||||
if (tb->hash[i] != NULL && tb->hash[i] != &EMPTY)
|
{
|
||||||
{
|
int h = tb->hash[i]->hash%newsize;
|
||||||
int h = tb->hash[i]->hash%newsize;
|
while (newhash[h])
|
||||||
while (newhash[h])
|
h = (h+1)%newsize;
|
||||||
h = (h+1)%newsize;
|
newhash[h] = tb->hash[i];
|
||||||
newhash[h] = tb->hash[i];
|
tb->nuse++;
|
||||||
tb->nuse++;
|
}
|
||||||
}
|
luaI_free(tb->hash);
|
||||||
luaI_free(tb->hash);
|
|
||||||
}
|
|
||||||
tb->size = newsize;
|
tb->size = newsize;
|
||||||
tb->hash = newhash;
|
tb->hash = newhash;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user