Merge pull request #5461 from bkoropoff/serial-crash

Fix crash importing small disc images
This commit is contained in:
Twinaphex 2017-09-21 16:35:27 +02:00 committed by GitHub
commit 7af2cc3b60

View File

@ -337,13 +337,15 @@ int detect_system(intfstream_t *fd, const char **system_name)
int rv;
char magic[MAGIC_LEN];
int i;
ssize_t read;
RARCH_LOG("%s\n", msg_hash_to_str(MSG_COMPARING_WITH_KNOWN_MAGIC_NUMBERS));
for (i = 0; MAGIC_NUMBERS[i].system_name != NULL; i++)
{
intfstream_seek(fd, MAGIC_NUMBERS[i].offset, SEEK_SET);
if (intfstream_read(fd, magic, MAGIC_LEN) < MAGIC_LEN)
read = intfstream_read(fd, magic, MAGIC_LEN);
if (read < 0)
{
RARCH_LOG("Could not read data at offset %d: %s\n",
MAGIC_NUMBERS[i].offset, strerror(errno));
@ -351,6 +353,9 @@ int detect_system(intfstream_t *fd, const char **system_name)
goto clean;
}
if (read < MAGIC_LEN)
continue;
if (string_is_equal_fast(MAGIC_NUMBERS[i].magic, magic, MAGIC_LEN))
{
*system_name = MAGIC_NUMBERS[i].system_name;