From 4f2fc17a8f61fd5524ecafa8f26fff11b967235f Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 2 Jul 2010 18:16:50 -0700 Subject: [PATCH] Fixed staging buffers reallocating on every operation (bug 3820, r=fyren+fyren). --- sourcepawn/compiler/sc7.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sourcepawn/compiler/sc7.c b/sourcepawn/compiler/sc7.c index 82096c25..6d5e3fdd 100644 --- a/sourcepawn/compiler/sc7.c +++ b/sourcepawn/compiler/sc7.c @@ -82,25 +82,25 @@ static char *stgpipe=NULL; static int pipemax=0; /* current size of the stage pipe, a second staging buffer */ static int pipeidx=0; -#define CHECK_STGBUFFER(index) if ((int)(index)>=stgmax) grow_stgbuffer(&stgbuf, stgmax, (index)+1) -#define CHECK_STGPIPE(index) if ((int)(index)>=pipemax) grow_stgbuffer(&stgpipe, pipemax, (index)+1) +#define CHECK_STGBUFFER(index) if ((int)(index)>=stgmax) grow_stgbuffer(&stgbuf, &stgmax, (index)+1) +#define CHECK_STGPIPE(index) if ((int)(index)>=pipemax) grow_stgbuffer(&stgpipe, &pipemax, (index)+1) -static void grow_stgbuffer(char **buffer, int curmax, int requiredsize) +static void grow_stgbuffer(char **buffer, int *curmax, int requiredsize) { char *p; int clear= (*buffer==NULL); /* if previously none, empty buffer explicitly */ - assert(curmaxsSTG_MAX) error(102,"staging buffer"); /* staging buffer overflow (fatal error) */ - curmax=requiredsize+sSTG_GROW; + *curmax=requiredsize+sSTG_GROW; if (*buffer!=NULL) - p=(char *)realloc(*buffer,curmax*sizeof(char)); + p=(char *)realloc(*buffer,*curmax*sizeof(char)); else - p=(char *)malloc(curmax*sizeof(char)); + p=(char *)malloc(*curmax*sizeof(char)); if (p==NULL) error(102,"staging buffer"); /* staging buffer overflow (fatal error) */ *buffer=p;