Prevent 'dereference before null check'

This commit is contained in:
twinaphex 2017-01-18 17:53:25 +01:00
parent b9104f38b8
commit aa47903520

View File

@ -69,63 +69,67 @@ void task_file_load_handler(retro_task_t *task)
{ {
nbio_handle_t *nbio = (nbio_handle_t*)task->state; nbio_handle_t *nbio = (nbio_handle_t*)task->state;
switch (nbio->status) if (nbio)
{ {
case NBIO_STATUS_INIT: switch (nbio->status)
if (nbio && !string_is_empty(nbio->path)) {
{ case NBIO_STATUS_INIT:
const char *fullpath = nbio->path; if (nbio && !string_is_empty(nbio->path))
struct nbio_t *handle = nbio_open(fullpath, NBIO_READ);
if (handle)
{ {
nbio->handle = handle; const char *fullpath = nbio->path;
nbio->status = NBIO_STATUS_TRANSFER; struct nbio_t *handle = nbio_open(fullpath, NBIO_READ);
if (strstr(fullpath, file_path_str(FILE_PATH_PNG_EXTENSION))) if (handle)
nbio->image_type = IMAGE_TYPE_PNG; {
else if (strstr(fullpath, file_path_str(FILE_PATH_JPEG_EXTENSION)) nbio->handle = handle;
|| strstr(fullpath, file_path_str(FILE_PATH_JPG_EXTENSION))) nbio->status = NBIO_STATUS_TRANSFER;
nbio->image_type = IMAGE_TYPE_JPEG;
else if (strstr(fullpath, file_path_str(FILE_PATH_BMP_EXTENSION)))
nbio->image_type = IMAGE_TYPE_BMP;
else if (strstr(fullpath, file_path_str(FILE_PATH_TGA_EXTENSION)))
nbio->image_type = IMAGE_TYPE_TGA;
nbio_begin_read(handle); if (strstr(fullpath, file_path_str(FILE_PATH_PNG_EXTENSION)))
return; nbio->image_type = IMAGE_TYPE_PNG;
else if (strstr(fullpath, file_path_str(FILE_PATH_JPEG_EXTENSION))
|| strstr(fullpath, file_path_str(FILE_PATH_JPG_EXTENSION)))
nbio->image_type = IMAGE_TYPE_JPEG;
else if (strstr(fullpath, file_path_str(FILE_PATH_BMP_EXTENSION)))
nbio->image_type = IMAGE_TYPE_BMP;
else if (strstr(fullpath, file_path_str(FILE_PATH_TGA_EXTENSION)))
nbio->image_type = IMAGE_TYPE_TGA;
nbio_begin_read(handle);
return;
}
else
task_set_cancelled(task, true);
} }
else break;
case NBIO_STATUS_TRANSFER_PARSE:
if (task_file_transfer_iterate_parse(nbio) == -1)
task_set_cancelled(task, true); task_set_cancelled(task, true);
} nbio->status = NBIO_STATUS_TRANSFER_PARSE_FREE;
break; break;
case NBIO_STATUS_TRANSFER_PARSE: case NBIO_STATUS_TRANSFER:
if (task_file_transfer_iterate_parse(nbio) == -1) if (task_file_transfer_iterate_transfer(nbio) == -1)
task_set_cancelled(task, true); nbio->status = NBIO_STATUS_TRANSFER_PARSE;
nbio->status = NBIO_STATUS_TRANSFER_PARSE_FREE; break;
break; case NBIO_STATUS_TRANSFER_PARSE_FREE:
case NBIO_STATUS_TRANSFER: case NBIO_STATUS_POLL:
if (task_file_transfer_iterate_transfer(nbio) == -1) default:
nbio->status = NBIO_STATUS_TRANSFER_PARSE; break;
break; }
case NBIO_STATUS_TRANSFER_PARSE_FREE:
case NBIO_STATUS_POLL:
default:
break;
}
switch (nbio->image_type) switch (nbio->image_type)
{ {
case IMAGE_TYPE_PNG: case IMAGE_TYPE_PNG:
case IMAGE_TYPE_JPEG: case IMAGE_TYPE_JPEG:
case IMAGE_TYPE_TGA: case IMAGE_TYPE_TGA:
case IMAGE_TYPE_BMP: case IMAGE_TYPE_BMP:
if (!task_image_load_handler(task)) if (!task_image_load_handler(task))
task_set_finished(task, true); task_set_finished(task, true);
break; break;
case 0: case 0:
if (nbio->is_finished) if (nbio->is_finished)
task_set_finished(task, true); task_set_finished(task, true);
break; break;
}
} }
if (task_get_cancelled(task)) if (task_get_cancelled(task))