Merge pull request #9126 from LazyBumHorse/playlist

fix use of filestream_getc in playlist format detection
This commit is contained in:
Twinaphex 2019-07-18 19:27:34 +02:00 committed by GitHub
commit 2cb501930d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include <libretro.h> #include <libretro.h>
#include <boolean.h> #include <boolean.h>
@ -1843,21 +1844,18 @@ static bool playlist_read_file(
/* Detect format of playlist */ /* Detect format of playlist */
{ {
char test_char = 0; int test_char;
/* Read file until we find the first non-whitespace /* Read file until we find the first printable non-whitespace
* ASCII character */ * ASCII character */
while ((test_char <= 0x20) || (test_char >= 0x7F)) do
{ {
test_char = filestream_getc(file); test_char = filestream_getc(file);
/* Sanity check: if (test_char == EOF) /* read error or end of file */
* - If filestream_getc() returns 0, stream is invalid
* - If filestream_getc() returns EOF, then no non-whitespace
* ASCII characters were found */
if ((test_char == 0) || (test_char == EOF))
goto end; goto end;
} }
while (!isgraph(test_char) || test_char > 0x7F);
if (test_char == '{') if (test_char == '{')
{ {
@ -1989,7 +1987,7 @@ static bool playlist_read_file(
} }
/* Search backwards for the next two newlines */ /* Search backwards for the next two newlines */
while(metadata_counter < 2) while (metadata_counter < 2)
{ {
filestream_seek(file, -2, SEEK_CUR); filestream_seek(file, -2, SEEK_CUR);
if (filestream_error(file)) if (filestream_error(file))