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

@ -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));
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));
if (listing_v)
RARCH_ERR("Vertex:\n%s\n", (char*)listing_v->lpVtbl->GetBufferPointer(listing_v));
listing_f->lpVtbl->Release(listing_f);
}
if (listing_v)
{
RARCH_ERR("Vertex:\n%s\n", (char*)listing_v->lpVtbl->GetBufferPointer(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));
if (listing_v)
RARCH_ERR("Vertex:\n%s\n", (char*)listing_v->lpVtbl->GetBufferPointer(listing_v));
listing_f->lpVtbl->Release(listing_f);
}
if (listing_v)
{
RARCH_ERR("Vertex:\n%s\n", (char*)listing_v->lpVtbl->GetBufferPointer(listing_v));
listing_v->lpVtbl->Release(listing_v);
}
return false;
}

View File

@ -92,6 +92,8 @@ bool file_list_insert(file_list_t *list,
struct item_file *copy = (struct item_file*)
malloc(sizeof(struct item_file));
if (copy)
{
copy->path = NULL;
copy->label = NULL;
copy->alt = NULL;
@ -108,6 +110,7 @@ bool file_list_insert(file_list_t *list,
free(copy);
}
}
list->list[idx].path = NULL;
list->list[idx].label = NULL;

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);
@ -529,10 +529,13 @@ struct string_list *string_list_clone(const struct string_list *src)
if (len != 0)
{
char *result = (char*)malloc(len + 1);
if (result)
{
strcpy(result, _src);
dest->elems[i].data = result;
}
}
}
return dest;
}

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

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,6 +367,7 @@ 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));
if (raw_image_data)
memcpy(raw_image_data,
raw_image_file_data + 54 * sizeof(uint8_t),
image_width * image_height * 3 * sizeof(uint8_t));
@ -835,11 +842,15 @@ 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);
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)
goto finish;
@ -1144,6 +1155,7 @@ finish:
free(bmp64_buffer);
if (sys_lbl)
free(sys_lbl);
sys_lbl = NULL;
if (jsonwriter)
rjsonwriter_free(jsonwriter);
return !error;