Fix false positives in readstr

Reading the byte `EOF & 0xFF` would cause an incorrect termination
This commit is contained in:
ISSOtm
2019-10-11 01:00:13 +02:00
parent f2e1b7d868
commit 8a59994c0d

View File

@@ -117,6 +117,7 @@ static char *readstr(FILE *file)
do { do {
/* Prepare going to next char */ /* Prepare going to next char */
index++; index++;
/* If the buffer isn't suitable to write the next char... */ /* If the buffer isn't suitable to write the next char... */
if (index >= capacity || !str) { if (index >= capacity || !str) {
capacity *= 2; capacity *= 2;
@@ -125,10 +126,13 @@ static char *readstr(FILE *file)
if (!str) if (!str)
return NULL; return NULL;
} }
/* Read char */ /* Read char */
str[index] = getc(file); int byte = getc(file);
if (str[index] == EOF)
if (byte == EOF)
return NULL; return NULL;
str[index] = byte;
} while (str[index]); } while (str[index]);
return str; return str;
} }