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) command_t* command_network_new(uint16_t port)
{ {
struct addrinfo *res = NULL; 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( command_network_t *netcmd = (command_network_t*)calloc(
1, sizeof(command_network_t)); 1, sizeof(command_network_t));
int fd = socket_init( int fd = socket_init(

View File

@ -99,8 +99,12 @@ void libretro_dummy_retro_init(void)
#endif #endif
dummy_frame_buf = (uint16_t*)calloc(frame_buf_width * frame_buf_height, sizeof(uint16_t)); 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) void libretro_dummy_retro_deinit(void)

View File

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

View File

@ -92,21 +92,24 @@ bool file_list_insert(file_list_t *list,
struct item_file *copy = (struct item_file*) struct item_file *copy = (struct item_file*)
malloc(sizeof(struct item_file)); malloc(sizeof(struct item_file));
copy->path = NULL; if (copy)
copy->label = NULL; {
copy->alt = NULL; copy->path = NULL;
copy->type = 0; copy->label = NULL;
copy->directory_ptr = 0; copy->alt = NULL;
copy->entry_idx = 0; copy->type = 0;
copy->userdata = NULL; copy->directory_ptr = 0;
copy->actiondata = NULL; 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-1], &list->list[i], sizeof(struct item_file));
memcpy(&list->list[i], copy, sizeof(struct item_file)); memcpy(&list->list[i], copy, sizeof(struct item_file));
free(copy); free(copy);
}
} }
list->list[idx].path = NULL; list->list[idx].path = NULL;

View File

@ -37,7 +37,7 @@ static bool string_list_deinitialize_internal(struct string_list *list)
if (list->elems) if (list->elems)
{ {
unsigned i; unsigned i;
for (i = 0; i < list->size; i++) for (i = 0; i < (unsigned)list->size; i++)
{ {
if (list->elems[i].data) if (list->elems[i].data)
free(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) if (!dest)
return NULL; return NULL;
dest->elems = NULL; dest->elems = NULL;
dest->size = src->size; dest->size = src->size;
if (src->cap < dest->size) if (src->cap < dest->size)
dest->cap = dest->size; dest->cap = dest->size;
else else
dest->cap = src->cap; dest->cap = src->cap;
if (!(elems = (struct string_list_elem*) if (!(elems = (struct string_list_elem*)
calloc(dest->cap, sizeof(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; return NULL;
} }
dest->elems = elems; dest->elems = elems;
for (i = 0; i < src->size; i++) 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) if (len != 0)
{ {
char *result = (char*)malloc(len + 1); char *result = (char*)malloc(len + 1);
strcpy(result, _src); if (result)
dest->elems[i].data = 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) RFILE* filestream_open(const char *path, unsigned mode, unsigned hints)
{ {
struct retro_vfs_file_handle *fp = NULL; struct retro_vfs_file_handle *fp = NULL;
RFILE* output = NULL; RFILE* output = (RFILE*)malloc(sizeof(RFILE));
if (!output)
return NULL;
if (filestream_open_cb) if (filestream_open_cb)
fp = (struct retro_vfs_file_handle*) 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); retro_vfs_file_open_impl(path, mode, hints);
if (!fp) if (!fp)
{
free(output);
return NULL; return NULL;
}
output = (RFILE*)malloc(sizeof(RFILE));
output->error_flag = false; output->error_flag = false;
output->hfile = fp; output->hfile = fp;
return output; 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->size)
{ {
if (stream->buf)
free(stream->buf);
stream->buf = malloc(len); stream->buf = malloc(len);
if (!stream->buf) if (!stream->buf)
return false; return false;

View File

@ -128,12 +128,6 @@ static uint64_t bps_decode(struct bps_data *bps)
return data; 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( static enum patch_error bps_apply_patch(
const uint8_t *modify_data, uint64_t modify_length, const uint8_t *modify_data, uint64_t modify_length,
const uint8_t *source_data, uint64_t source_length, const uint8_t *source_data, uint64_t source_length,
@ -208,12 +202,20 @@ static enum patch_error bps_apply_patch(
{ {
case SOURCE_READ: case SOURCE_READ:
while (length--) 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; break;
case TARGET_READ: case TARGET_READ:
while (length--) 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; break;
case SOURCE_COPY: case SOURCE_COPY:
@ -231,13 +233,21 @@ static enum patch_error bps_apply_patch(
{ {
bps.source_offset += offset; bps.source_offset += offset;
while (length--) 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 else
{ {
bps.target_offset += offset; bps.target_offset += offset;
while (length--) 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;
} }
break; break;

View File

@ -239,6 +239,9 @@ static bool screenshot_dump(
screenshot_task_state_t *state = (screenshot_task_state_t*) screenshot_task_state_t *state = (screenshot_task_state_t*)
calloc(1, sizeof(*state)); calloc(1, sizeof(*state));
if (!state)
return false;
/* If fullpath is true, name_base already contains a /* If fullpath is true, name_base already contains a
* static path + filename to save the screenshot to. */ * static path + filename to save the screenshot to. */
if (fullpath) if (fullpath)

View File

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