mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Fix false positives in readstr
Reading the byte `EOF & 0xFF` would cause an incorrect termination
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user