diff --git a/source/compiler/sc7.c b/source/compiler/sc7.c index 5981efc..91759dc 100644 --- a/source/compiler/sc7.c +++ b/source/compiler/sc7.c @@ -1254,6 +1254,7 @@ static void stgopt(char *start,char *end,int (*outputfunc)(char *str)); static char *stgbuf=NULL; static int stgmax=0; /* current size of the staging buffer */ +static int stglen=0; /* current length of the staging buffer */ static char *stgpipe=NULL; static int pipemax=0; /* current size of the stage pipe, a second staging buffer */ @@ -1364,10 +1365,12 @@ static int filewrite(char *str) * Global references: stgidx (altered) * stgbuf (altered) * staging (referred to only) + * stglen (altered) */ SC_FUNC void stgwrite(const char *st) { int len; + int st_len; if (staging) { assert(stgidx==0 || stgbuf!=NULL); /* staging buffer must be valid if there is (apparently) something in it */ @@ -1380,13 +1383,16 @@ SC_FUNC void stgwrite(const char *st) CHECK_STGBUFFER(stgidx); stgbuf[stgidx++]='\0'; } else { - len=(stgbuf!=NULL) ? strlen(stgbuf) : 0; - CHECK_STGBUFFER(len+strlen(st)+1); - strcat(stgbuf,st); - len=strlen(stgbuf); + len=(stgbuf!=NULL) ? stglen : 0; + st_len=strlen(st); + CHECK_STGBUFFER(len+st_len+1); + memcpy(stgbuf + len, st, st_len + 1); //strcat(stgbuf,st); + len=len+st_len; + stglen=len; if (len>0 && stgbuf[len-1]=='\n') { filewrite(stgbuf); stgbuf[0]='\0'; + stglen=0; } /* if */ } /* if */ }