Rearranged the algorithm in get_text() to fix a memory overrun.

This commit is contained in:
dtrg 2006-07-21 09:28:36 +00:00
parent a1ba8c6d3f
commit 685e85002e

View file

@ -608,7 +608,6 @@ get_text(formals, length)
register unsigned int text_size; register unsigned int text_size;
char *text = Malloc(text_size = ITEXTSIZE); char *text = Malloc(text_size = ITEXTSIZE);
register unsigned int pos = 0; register unsigned int pos = 0;
int match = 0;
LoadChar(c); LoadChar(c);
@ -622,19 +621,15 @@ get_text(formals, length)
*/ */
text[pos++] = ' '; text[pos++] = ' ';
++LineNumber; ++LineNumber;
LoadChar(c);
} }
else { else
text[pos++] = '\\'; text[pos++] = '\\';
if (pos == text_size) if (pos == text_size)
text = Realloc(text, text_size <<= 1); text = Realloc(text, text_size <<= 1);
text[pos++] = c;
if (pos == text_size)
text = Realloc(text, text_size <<= 1);
}
LoadChar(c);
} }
else else
if (match == 0 && c == '/') { if ( c == '/') {
LoadChar(c); LoadChar(c);
if (c == '*') { if (c == '*') {
skipcomment(); skipcomment();
@ -647,19 +642,7 @@ get_text(formals, length)
text = Realloc(text, text_size <<= 1); text = Realloc(text, text_size <<= 1);
} }
else else
if (c == '\'' || c == '"') { if (formals && class(c) == STIDF) {
text[pos++] = c;
if (pos == text_size)
text = Realloc(text, text_size <<= 1);
if (match == c) {
match = 0;
} else if (match == 0) {
match = c;
}
LoadChar(c);
}
else
if (match == 0 && formals && class(c) == STIDF) {
char id_buf[IDFSIZE + 1]; char id_buf[IDFSIZE + 1];
register char *idp = id_buf; register char *idp = id_buf;
int n; int n;