1
0
mirror of https://github.com/libretro/RetroArch synced 2024-06-28 22:44:21 +00:00

iFix warnings picked up by -fanalyzer

This commit is contained in:
libretroadmin 2024-05-23 23:49:59 +02:00
parent b38304cae5
commit 3e85a17d7a
11 changed files with 108 additions and 59 deletions

View File

@ -230,7 +230,7 @@ static void command_network_poll(command_t *handle)
command_t* command_network_new(uint16_t port)
{
struct addrinfo *res = NULL;
command_t *cmd = (command_t*)calloc(1, sizeof(command_t));
command_t *cmd = (command_t*)calloc(1, sizeof(*cmd));
command_network_t *netcmd = (command_network_t*)calloc(
1, sizeof(command_network_t));
int fd = socket_init(

View File

@ -443,7 +443,7 @@ struct retro_core_options_v2 *core_option_manager_convert_v2_intl(
options_v2_us->categories[i].desc : local_desc;
option_v2_cats[i].info = string_is_empty(local_info) ?
options_v2_us->categories[i].info : local_info;
}
/* Loop through options... */
@ -1404,7 +1404,7 @@ bool core_option_manager_get_category_visible(core_option_manager_t *opt,
nested_list_item_t *category_item = NULL;
nested_list_t *option_list = NULL;
if ( !opt
if ( !opt
|| string_is_empty(key))
return false;
@ -1649,7 +1649,7 @@ const char *core_option_manager_get_val_label(core_option_manager_t *opt,
{
struct core_option *option = NULL;
if ( !opt
if ( !opt
|| (idx >= opt->size))
return NULL;

View File

@ -99,8 +99,12 @@ void libretro_dummy_retro_init(void)
#endif
dummy_frame_buf = (uint16_t*)calloc(frame_buf_width * frame_buf_height, sizeof(uint16_t));
for (i = 0; i < (unsigned)(frame_buf_width * frame_buf_height); i++)
dummy_frame_buf[i] = 4 << 5;
if (dummy_frame_buf)
{
for (i = 0; i < (unsigned)(frame_buf_width * frame_buf_height); i++)
dummy_frame_buf[i] = 4 << 5;
}
}
void libretro_dummy_retro_deinit(void)

View File

@ -469,11 +469,15 @@ static bool d3d9_hlsl_load_program_from_file(
error:
RARCH_ERR("Cg/HLSL error:\n");
if (listing_f)
{
RARCH_ERR("Fragment:\n%s\n", (char*)listing_f->lpVtbl->GetBufferPointer(listing_f));
listing_f->lpVtbl->Release(listing_f);
}
if (listing_v)
{
RARCH_ERR("Vertex:\n%s\n", (char*)listing_v->lpVtbl->GetBufferPointer(listing_v));
listing_f->lpVtbl->Release(listing_f);
listing_v->lpVtbl->Release(listing_v);
listing_v->lpVtbl->Release(listing_v);
}
return false;
}
@ -518,12 +522,15 @@ static bool d3d9_hlsl_load_program(
error:
RARCH_ERR("Cg/HLSL error:\n");
if (listing_f)
{
RARCH_ERR("Fragment:\n%s\n", (char*)listing_f->lpVtbl->GetBufferPointer(listing_f));
listing_f->lpVtbl->Release(listing_f);
}
if (listing_v)
{
RARCH_ERR("Vertex:\n%s\n", (char*)listing_v->lpVtbl->GetBufferPointer(listing_v));
listing_f->lpVtbl->Release(listing_f);
listing_v->lpVtbl->Release(listing_v);
listing_v->lpVtbl->Release(listing_v);
}
return false;
}

View File

@ -92,21 +92,24 @@ bool file_list_insert(file_list_t *list,
struct item_file *copy = (struct item_file*)
malloc(sizeof(struct item_file));
copy->path = NULL;
copy->label = NULL;
copy->alt = NULL;
copy->type = 0;
copy->directory_ptr = 0;
copy->entry_idx = 0;
copy->userdata = NULL;
copy->actiondata = NULL;
if (copy)
{
copy->path = NULL;
copy->label = NULL;
copy->alt = NULL;
copy->type = 0;
copy->directory_ptr = 0;
copy->entry_idx = 0;
copy->userdata = NULL;
copy->actiondata = NULL;
memcpy(copy, &list->list[i-1], sizeof(struct item_file));
memcpy(copy, &list->list[i-1], sizeof(struct item_file));
memcpy(&list->list[i-1], &list->list[i], sizeof(struct item_file));
memcpy(&list->list[i], copy, sizeof(struct item_file));
memcpy(&list->list[i-1], &list->list[i], sizeof(struct item_file));
memcpy(&list->list[i], copy, sizeof(struct item_file));
free(copy);
free(copy);
}
}
list->list[idx].path = NULL;
@ -318,8 +321,8 @@ bool file_list_search(const file_list_t *list, const char *needle, size_t *idx)
for (i = 0; i < list->size; i++)
{
const char *str = NULL;
const char *alt = list->list[i].alt
? list->list[i].alt
const char *alt = list->list[i].alt
? list->list[i].alt
: list->list[i].path;
if (!alt)

View File

@ -37,7 +37,7 @@ static bool string_list_deinitialize_internal(struct string_list *list)
if (list->elems)
{
unsigned i;
for (i = 0; i < list->size; i++)
for (i = 0; i < (unsigned)list->size; i++)
{
if (list->elems[i].data)
free(list->elems[i].data);
@ -502,12 +502,12 @@ struct string_list *string_list_clone(const struct string_list *src)
if (!dest)
return NULL;
dest->elems = NULL;
dest->size = src->size;
dest->elems = NULL;
dest->size = src->size;
if (src->cap < dest->size)
dest->cap = dest->size;
else
dest->cap = src->cap;
dest->cap = dest->size;
else
dest->cap = src->cap;
if (!(elems = (struct string_list_elem*)
calloc(dest->cap, sizeof(struct string_list_elem))))
@ -516,7 +516,7 @@ struct string_list *string_list_clone(const struct string_list *src)
return NULL;
}
dest->elems = elems;
dest->elems = elems;
for (i = 0; i < src->size; i++)
{
@ -529,8 +529,11 @@ struct string_list *string_list_clone(const struct string_list *src)
if (len != 0)
{
char *result = (char*)malloc(len + 1);
strcpy(result, _src);
dest->elems[i].data = result;
if (result)
{
strcpy(result, _src);
dest->elems[i].data = result;
}
}
}

View File

@ -155,7 +155,10 @@ int64_t filestream_truncate(RFILE *stream, int64_t length)
RFILE* filestream_open(const char *path, unsigned mode, unsigned hints)
{
struct retro_vfs_file_handle *fp = NULL;
RFILE* output = NULL;
RFILE* output = (RFILE*)malloc(sizeof(RFILE));
if (!output)
return NULL;
if (filestream_open_cb)
fp = (struct retro_vfs_file_handle*)
@ -165,9 +168,11 @@ RFILE* filestream_open(const char *path, unsigned mode, unsigned hints)
retro_vfs_file_open_impl(path, mode, hints);
if (!fp)
{
free(output);
return NULL;
}
output = (RFILE*)malloc(sizeof(RFILE));
output->error_flag = false;
output->hfile = fp;
return output;

View File

@ -243,6 +243,8 @@ bool netstream_write(netstream_t *stream, const void *data, size_t len)
{
if (!stream->size)
{
if (stream->buf)
free(stream->buf);
stream->buf = malloc(len);
if (!stream->buf)
return false;

View File

@ -128,12 +128,6 @@ static uint64_t bps_decode(struct bps_data *bps)
return data;
}
static void bps_write(struct bps_data *bps, uint8_t data)
{
bps->target_data[bps->output_offset++] = data;
bps->target_checksum = ~(encoding_crc32(~bps->target_checksum, &data, 1));
}
static enum patch_error bps_apply_patch(
const uint8_t *modify_data, uint64_t modify_length,
const uint8_t *source_data, uint64_t source_length,
@ -208,12 +202,20 @@ static enum patch_error bps_apply_patch(
{
case SOURCE_READ:
while (length--)
bps_write(&bps, bps.source_data[bps.output_offset]);
{
uint8_t data = bps.source_data[bps.output_offset];
bps.target_data[bps.output_offset++] = data;
bps.target_checksum = ~(encoding_crc32(~bps.target_checksum, &data, 1));
}
break;
case TARGET_READ:
while (length--)
bps_write(&bps, bps_read(&bps));
{
uint8_t data = bps_read(&bps);
bps.target_data[bps.output_offset++] = data;
bps.target_checksum = ~(encoding_crc32(~bps.target_checksum, &data, 1));
}
break;
case SOURCE_COPY:
@ -231,13 +233,21 @@ static enum patch_error bps_apply_patch(
{
bps.source_offset += offset;
while (length--)
bps_write(&bps, bps.source_data[bps.source_offset++]);
{
uint8_t data = bps.source_data[bps.source_offset++];
bps.target_data[bps.output_offset++] = data;
bps.target_checksum = ~(encoding_crc32(~bps.target_checksum, &data, 1));
}
}
else
{
bps.target_offset += offset;
while (length--)
bps_write(&bps, bps.target_data[bps.target_offset++]);
{
uint8_t data = bps.target_data[bps.target_offset++];
bps.target_data[bps.output_offset++] = data;
bps.target_checksum = ~(encoding_crc32(~bps.target_checksum, &data, 1));
}
break;
}
break;

View File

@ -239,7 +239,10 @@ static bool screenshot_dump(
screenshot_task_state_t *state = (screenshot_task_state_t*)
calloc(1, sizeof(*state));
/* If fullpath is true, name_base already contains a
if (!state)
return false;
/* If fullpath is true, name_base already contains a
* static path + filename to save the screenshot to. */
if (fullpath)
strlcpy(state->filename, name_base, sizeof(state->filename));
@ -261,7 +264,7 @@ static bool screenshot_dump(
#endif
if (savestate)
state->flags |= SS_TASK_FLAG_SILENCE;
if (history_list_enable)
state->flags |= SS_TASK_FLAG_HISTORY_LIST_ENABLE;
state->pixel_format_type = pixel_format_type;
@ -329,7 +332,7 @@ static bool screenshot_dump(
}
else
{
size_t len = strlcpy(state->shotname,
size_t len = strlcpy(state->shotname,
path_basename_nocompression(name_base),
sizeof(state->shotname));
strlcpy(state->shotname + len,
@ -548,7 +551,7 @@ bool take_screenshot(
bool ret = false;
uint32_t runloop_flags = runloop_get_flags();
settings_t *settings = config_get_ptr();
video_driver_state_t *video_st = video_state_get_ptr();
video_driver_state_t *video_st = video_state_get_ptr();
bool video_gpu_screenshot = settings->bools.video_gpu_screenshot;
bool supports_viewport_read = video_st->current_video->read_viewport
&& (video_st->current_video->viewport_info);

View File

@ -121,11 +121,17 @@ static void call_auto_translate_task(
return;
mode = (int*)malloc(sizeof(int));
*mode = ai_service_mode;
t->user_data = NULL;
t->handler = task_auto_translate_handler;
t->user_data = mode;
t->mute = true;
if (mode)
{
*mode = ai_service_mode;
t->user_data = mode;
}
task_queue_push(t);
}
}
@ -361,9 +367,10 @@ static void handle_translation_cb(
((uint32_t) ((uint8_t)raw_image_file_data[23]) << 8) +
((uint32_t) ((uint8_t)raw_image_file_data[22]) << 0);
raw_image_data = (void*)malloc(image_width * image_height * 3 * sizeof(uint8_t));
memcpy(raw_image_data,
raw_image_file_data + 54 * sizeof(uint8_t),
image_width * image_height * 3 * sizeof(uint8_t));
if (raw_image_data)
memcpy(raw_image_data,
raw_image_file_data + 54 * sizeof(uint8_t),
image_width * image_height * 3 * sizeof(uint8_t));
}
/* PNG coming back from the url */
else if (raw_image_file_data[1] == 'P'
@ -835,10 +842,14 @@ bool run_translation_service(settings_t *settings, bool paused)
lbl = path_basename(path_get(RARCH_PATH_BASENAME));
lbl_len = strlen(lbl);
sys_lbl = (char*)malloc(lbl_len + sys_id_len + 3);
memcpy(sys_lbl, sys_id, sys_id_len);
memcpy(sys_lbl + sys_id_len, "__", 2);
memcpy(sys_lbl + 2 + sys_id_len, lbl, lbl_len);
sys_lbl[sys_id_len + 2 + lbl_len] = '\0';
if (sys_lbl)
{
memcpy(sys_lbl, sys_id, sys_id_len);
memcpy(sys_lbl + sys_id_len, "__", 2);
memcpy(sys_lbl + 2 + sys_id_len, lbl, lbl_len);
sys_lbl[sys_id_len + 2 + lbl_len] = '\0';
}
}
if (!scaler)
@ -1144,6 +1155,7 @@ finish:
free(bmp64_buffer);
if (sys_lbl)
free(sys_lbl);
sys_lbl = NULL;
if (jsonwriter)
rjsonwriter_free(jsonwriter);
return !error;