Buffer overflow memory errors.

This commit is contained in:
carl 2019-03-31 00:52:37 +08:00
parent 9bc3ffe6ec
commit 4f2c482416

View file

@ -395,6 +395,18 @@ char* readident(int c)
} }
#endif #endif
static void need_stringbuf()
{
if (!maxstring)
{
maxstring = STRINGMAX;
if ((stringbuf = malloc(maxstring)) == 0)
{
fatal("out of memory");
}
}
}
static int innumber(int c) static int innumber(int c)
{ {
char* p; char* p;
@ -464,11 +476,8 @@ floatconstant:
*p = '\0'; *p = '\0';
stringlen = p - num; stringlen = p - num;
if (stringlen > maxstring) need_stringbuf();
{ assert(stringlen < maxstring);
maxstring = stringlen;
stringbuf = realloc(stringbuf, maxstring);
}
strcpy(stringbuf, num); strcpy(stringbuf, num);
return NUMBERF; return NUMBERF;
} }
@ -478,14 +487,7 @@ static int instring(int termc)
char* p; char* p;
int c; int c;
if (!maxstring) need_stringbuf();
{
maxstring = STRINGMAX;
if ((stringbuf = malloc(maxstring)) == 0)
{
fatal("out of memory");
}
}
p = stringbuf; p = stringbuf;
for (;;) for (;;)
{ {