From 3e85a17d7a089ae34cd8a989e73ff8b01434728b Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Thu, 23 May 2024 23:49:59 +0200 Subject: [PATCH] iFix warnings picked up by -fanalyzer --- command.c | 2 +- core_option_manager.c | 6 ++--- cores/dynamic_dummy.c | 8 ++++-- gfx/drivers/d3d9hlsl.c | 17 +++++++++---- libretro-common/lists/file_list.c | 31 +++++++++++++----------- libretro-common/lists/string_list.c | 21 +++++++++------- libretro-common/streams/file_stream.c | 9 +++++-- libretro-common/streams/network_stream.c | 2 ++ tasks/task_patch.c | 30 +++++++++++++++-------- tasks/task_screenshot.c | 11 ++++++--- tasks/task_translation.c | 30 ++++++++++++++++------- 11 files changed, 108 insertions(+), 59 deletions(-) diff --git a/command.c b/command.c index 708c3cd29f..6cf74cced0 100644 --- a/command.c +++ b/command.c @@ -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( diff --git a/core_option_manager.c b/core_option_manager.c index 6c3c7c74fc..ec7e56b982 100644 --- a/core_option_manager.c +++ b/core_option_manager.c @@ -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; diff --git a/cores/dynamic_dummy.c b/cores/dynamic_dummy.c index e4a5134ae8..fc23656bfd 100644 --- a/cores/dynamic_dummy.c +++ b/cores/dynamic_dummy.c @@ -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) diff --git a/gfx/drivers/d3d9hlsl.c b/gfx/drivers/d3d9hlsl.c index 38d58ab150..7824584c8a 100644 --- a/gfx/drivers/d3d9hlsl.c +++ b/gfx/drivers/d3d9hlsl.c @@ -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; } diff --git a/libretro-common/lists/file_list.c b/libretro-common/lists/file_list.c index ba1bba7707..3f50563e95 100644 --- a/libretro-common/lists/file_list.c +++ b/libretro-common/lists/file_list.c @@ -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) diff --git a/libretro-common/lists/string_list.c b/libretro-common/lists/string_list.c index 1d485ac321..65be0bccbb 100644 --- a/libretro-common/lists/string_list.c +++ b/libretro-common/lists/string_list.c @@ -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; + } } } diff --git a/libretro-common/streams/file_stream.c b/libretro-common/streams/file_stream.c index 713b5d8c29..f6be82005a 100644 --- a/libretro-common/streams/file_stream.c +++ b/libretro-common/streams/file_stream.c @@ -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; diff --git a/libretro-common/streams/network_stream.c b/libretro-common/streams/network_stream.c index 068fd9509d..47f426b942 100644 --- a/libretro-common/streams/network_stream.c +++ b/libretro-common/streams/network_stream.c @@ -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; diff --git a/tasks/task_patch.c b/tasks/task_patch.c index 8eb30f5c56..39f3fe4152 100644 --- a/tasks/task_patch.c +++ b/tasks/task_patch.c @@ -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; diff --git a/tasks/task_screenshot.c b/tasks/task_screenshot.c index 80bcdbe692..7175f754c8 100644 --- a/tasks/task_screenshot.c +++ b/tasks/task_screenshot.c @@ -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); diff --git a/tasks/task_translation.c b/tasks/task_translation.c index de1bf62f87..1202d429da 100644 --- a/tasks/task_translation.c +++ b/tasks/task_translation.c @@ -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;