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 {
|
||||
/* Prepare going to next char */
|
||||
index++;
|
||||
|
||||
/* If the buffer isn't suitable to write the next char... */
|
||||
if (index >= capacity || !str) {
|
||||
capacity *= 2;
|
||||
@@ -125,10 +126,13 @@ static char *readstr(FILE *file)
|
||||
if (!str)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Read char */
|
||||
str[index] = getc(file);
|
||||
if (str[index] == EOF)
|
||||
int byte = getc(file);
|
||||
|
||||
if (byte == EOF)
|
||||
return NULL;
|
||||
str[index] = byte;
|
||||
} while (str[index]);
|
||||
return str;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user