Prevent explicit NULL dereferenced warnings

This commit is contained in:
twinaphex 2016-06-01 04:14:48 +02:00
parent bc3eb34da5
commit 5eb43846da
3 changed files with 26 additions and 19 deletions

View File

@ -1363,26 +1363,33 @@ bool rarch_environment_cb(unsigned cmd, void *data)
case RETRO_ENVIRONMENT_SET_MEMORY_MAPS:
{
unsigned i;
struct retro_memory_descriptor *descriptors;
const struct retro_memory_map *mmaps =
struct retro_memory_descriptor *descriptors = NULL;
const struct retro_memory_map *mmaps =
(const struct retro_memory_map*)data;
free((void*)system->mmaps.descriptors);
system->mmaps.num_descriptors = 0;
if (system)
{
RARCH_LOG("Environ SET_MEMORY_MAPS.\n");
free((void*)system->mmaps.descriptors);
system->mmaps.num_descriptors = 0;
descriptors = (struct retro_memory_descriptor*)
calloc(mmaps->num_descriptors,
sizeof(*system->mmaps.descriptors));
if (!descriptors)
return false;
system->mmaps.descriptors = descriptors;
memcpy((void*)system->mmaps.descriptors, mmaps->descriptors,
mmaps->num_descriptors * sizeof(*system->mmaps.descriptors));
system->mmaps.num_descriptors = mmaps->num_descriptors;
mmap_preprocess_descriptors(descriptors, mmaps->num_descriptors);
}
else
{
RARCH_WARN("Environ SET_MEMORY_MAPS, but system pointer not initialized..\n");
}
descriptors = (struct retro_memory_descriptor*)
calloc(mmaps->num_descriptors, sizeof(*system->mmaps.descriptors));
if (!descriptors)
return false;
system->mmaps.descriptors = descriptors;
memcpy((void*)system->mmaps.descriptors, mmaps->descriptors,
mmaps->num_descriptors * sizeof(*system->mmaps.descriptors));
system->mmaps.num_descriptors = mmaps->num_descriptors;
mmap_preprocess_descriptors(descriptors, mmaps->num_descriptors);
RARCH_LOG("Environ SET_MEMORY_MAPS.\n");
if (sizeof(void *) == 8)
RARCH_LOG(" ndx flags ptr offset start select disconn len addrspace\n");

View File

@ -133,7 +133,7 @@ static void gfx_ctx_x_destroy_resources(gfx_ctx_x_data_t *x)
x11_colormap_destroy();
if (x->g_should_reset_mode)
if (x->g_should_reset_mode && g_x11_dpy)
{
x11_exit_fullscreen(g_x11_dpy, &x->g_desktop_mode);
x->g_should_reset_mode = false;

View File

@ -451,7 +451,7 @@ static int file_archive_decompress_data_to_file(
}
end:
if (handle->data)
if (handle && handle->data)
free(handle->data);
return ret;
}