Skip to content

Commit 3e85a17

Browse files
committed
iFix warnings picked up by -fanalyzer
1 parent b38304c commit 3e85a17

11 files changed

Lines changed: 108 additions & 59 deletions

File tree

command.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static void command_network_poll(command_t *handle)
230230
command_t* command_network_new(uint16_t port)
231231
{
232232
struct addrinfo *res = NULL;
233-
command_t *cmd = (command_t*)calloc(1, sizeof(command_t));
233+
command_t *cmd = (command_t*)calloc(1, sizeof(*cmd));
234234
command_network_t *netcmd = (command_network_t*)calloc(
235235
1, sizeof(command_network_t));
236236
int fd = socket_init(

core_option_manager.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ struct retro_core_options_v2 *core_option_manager_convert_v2_intl(
443443
options_v2_us->categories[i].desc : local_desc;
444444
option_v2_cats[i].info = string_is_empty(local_info) ?
445445
options_v2_us->categories[i].info : local_info;
446-
446+
447447
}
448448

449449
/* Loop through options... */
@@ -1404,7 +1404,7 @@ bool core_option_manager_get_category_visible(core_option_manager_t *opt,
14041404
nested_list_item_t *category_item = NULL;
14051405
nested_list_t *option_list = NULL;
14061406

1407-
if ( !opt
1407+
if ( !opt
14081408
|| string_is_empty(key))
14091409
return false;
14101410

@@ -1649,7 +1649,7 @@ const char *core_option_manager_get_val_label(core_option_manager_t *opt,
16491649
{
16501650
struct core_option *option = NULL;
16511651

1652-
if ( !opt
1652+
if ( !opt
16531653
|| (idx >= opt->size))
16541654
return NULL;
16551655

cores/dynamic_dummy.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@ void libretro_dummy_retro_init(void)
9999
#endif
100100

101101
dummy_frame_buf = (uint16_t*)calloc(frame_buf_width * frame_buf_height, sizeof(uint16_t));
102-
for (i = 0; i < (unsigned)(frame_buf_width * frame_buf_height); i++)
103-
dummy_frame_buf[i] = 4 << 5;
102+
103+
if (dummy_frame_buf)
104+
{
105+
for (i = 0; i < (unsigned)(frame_buf_width * frame_buf_height); i++)
106+
dummy_frame_buf[i] = 4 << 5;
107+
}
104108
}
105109

106110
void libretro_dummy_retro_deinit(void)

gfx/drivers/d3d9hlsl.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,15 @@ static bool d3d9_hlsl_load_program_from_file(
469469
error:
470470
RARCH_ERR("Cg/HLSL error:\n");
471471
if (listing_f)
472+
{
472473
RARCH_ERR("Fragment:\n%s\n", (char*)listing_f->lpVtbl->GetBufferPointer(listing_f));
474+
listing_f->lpVtbl->Release(listing_f);
475+
}
473476
if (listing_v)
477+
{
474478
RARCH_ERR("Vertex:\n%s\n", (char*)listing_v->lpVtbl->GetBufferPointer(listing_v));
475-
listing_f->lpVtbl->Release(listing_f);
476-
listing_v->lpVtbl->Release(listing_v);
479+
listing_v->lpVtbl->Release(listing_v);
480+
}
477481

478482
return false;
479483
}
@@ -518,12 +522,15 @@ static bool d3d9_hlsl_load_program(
518522
error:
519523
RARCH_ERR("Cg/HLSL error:\n");
520524
if (listing_f)
525+
{
521526
RARCH_ERR("Fragment:\n%s\n", (char*)listing_f->lpVtbl->GetBufferPointer(listing_f));
527+
listing_f->lpVtbl->Release(listing_f);
528+
}
522529
if (listing_v)
530+
{
523531
RARCH_ERR("Vertex:\n%s\n", (char*)listing_v->lpVtbl->GetBufferPointer(listing_v));
524-
listing_f->lpVtbl->Release(listing_f);
525-
listing_v->lpVtbl->Release(listing_v);
526-
532+
listing_v->lpVtbl->Release(listing_v);
533+
}
527534
return false;
528535
}
529536

libretro-common/lists/file_list.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,24 @@ bool file_list_insert(file_list_t *list,
9292
struct item_file *copy = (struct item_file*)
9393
malloc(sizeof(struct item_file));
9494

95-
copy->path = NULL;
96-
copy->label = NULL;
97-
copy->alt = NULL;
98-
copy->type = 0;
99-
copy->directory_ptr = 0;
100-
copy->entry_idx = 0;
101-
copy->userdata = NULL;
102-
copy->actiondata = NULL;
95+
if (copy)
96+
{
97+
copy->path = NULL;
98+
copy->label = NULL;
99+
copy->alt = NULL;
100+
copy->type = 0;
101+
copy->directory_ptr = 0;
102+
copy->entry_idx = 0;
103+
copy->userdata = NULL;
104+
copy->actiondata = NULL;
103105

104-
memcpy(copy, &list->list[i-1], sizeof(struct item_file));
106+
memcpy(copy, &list->list[i-1], sizeof(struct item_file));
105107

106-
memcpy(&list->list[i-1], &list->list[i], sizeof(struct item_file));
107-
memcpy(&list->list[i], copy, sizeof(struct item_file));
108+
memcpy(&list->list[i-1], &list->list[i], sizeof(struct item_file));
109+
memcpy(&list->list[i], copy, sizeof(struct item_file));
108110

109-
free(copy);
111+
free(copy);
112+
}
110113
}
111114

112115
list->list[idx].path = NULL;
@@ -318,8 +321,8 @@ bool file_list_search(const file_list_t *list, const char *needle, size_t *idx)
318321
for (i = 0; i < list->size; i++)
319322
{
320323
const char *str = NULL;
321-
const char *alt = list->list[i].alt
322-
? list->list[i].alt
324+
const char *alt = list->list[i].alt
325+
? list->list[i].alt
323326
: list->list[i].path;
324327

325328
if (!alt)

libretro-common/lists/string_list.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static bool string_list_deinitialize_internal(struct string_list *list)
3737
if (list->elems)
3838
{
3939
unsigned i;
40-
for (i = 0; i < list->size; i++)
40+
for (i = 0; i < (unsigned)list->size; i++)
4141
{
4242
if (list->elems[i].data)
4343
free(list->elems[i].data);
@@ -502,12 +502,12 @@ struct string_list *string_list_clone(const struct string_list *src)
502502
if (!dest)
503503
return NULL;
504504

505-
dest->elems = NULL;
506-
dest->size = src->size;
505+
dest->elems = NULL;
506+
dest->size = src->size;
507507
if (src->cap < dest->size)
508-
dest->cap = dest->size;
509-
else
510-
dest->cap = src->cap;
508+
dest->cap = dest->size;
509+
else
510+
dest->cap = src->cap;
511511

512512
if (!(elems = (struct string_list_elem*)
513513
calloc(dest->cap, sizeof(struct string_list_elem))))
@@ -516,7 +516,7 @@ struct string_list *string_list_clone(const struct string_list *src)
516516
return NULL;
517517
}
518518

519-
dest->elems = elems;
519+
dest->elems = elems;
520520

521521
for (i = 0; i < src->size; i++)
522522
{
@@ -529,8 +529,11 @@ struct string_list *string_list_clone(const struct string_list *src)
529529
if (len != 0)
530530
{
531531
char *result = (char*)malloc(len + 1);
532-
strcpy(result, _src);
533-
dest->elems[i].data = result;
532+
if (result)
533+
{
534+
strcpy(result, _src);
535+
dest->elems[i].data = result;
536+
}
534537
}
535538
}
536539

libretro-common/streams/file_stream.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ int64_t filestream_truncate(RFILE *stream, int64_t length)
155155
RFILE* filestream_open(const char *path, unsigned mode, unsigned hints)
156156
{
157157
struct retro_vfs_file_handle *fp = NULL;
158-
RFILE* output = NULL;
158+
RFILE* output = (RFILE*)malloc(sizeof(RFILE));
159+
160+
if (!output)
161+
return NULL;
159162

160163
if (filestream_open_cb)
161164
fp = (struct retro_vfs_file_handle*)
@@ -165,9 +168,11 @@ RFILE* filestream_open(const char *path, unsigned mode, unsigned hints)
165168
retro_vfs_file_open_impl(path, mode, hints);
166169

167170
if (!fp)
171+
{
172+
free(output);
168173
return NULL;
174+
}
169175

170-
output = (RFILE*)malloc(sizeof(RFILE));
171176
output->error_flag = false;
172177
output->hfile = fp;
173178
return output;

libretro-common/streams/network_stream.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ bool netstream_write(netstream_t *stream, const void *data, size_t len)
243243
{
244244
if (!stream->size)
245245
{
246+
if (stream->buf)
247+
free(stream->buf);
246248
stream->buf = malloc(len);
247249
if (!stream->buf)
248250
return false;

tasks/task_patch.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,6 @@ static uint64_t bps_decode(struct bps_data *bps)
128128
return data;
129129
}
130130

131-
static void bps_write(struct bps_data *bps, uint8_t data)
132-
{
133-
bps->target_data[bps->output_offset++] = data;
134-
bps->target_checksum = ~(encoding_crc32(~bps->target_checksum, &data, 1));
135-
}
136-
137131
static enum patch_error bps_apply_patch(
138132
const uint8_t *modify_data, uint64_t modify_length,
139133
const uint8_t *source_data, uint64_t source_length,
@@ -208,12 +202,20 @@ static enum patch_error bps_apply_patch(
208202
{
209203
case SOURCE_READ:
210204
while (length--)
211-
bps_write(&bps, bps.source_data[bps.output_offset]);
205+
{
206+
uint8_t data = bps.source_data[bps.output_offset];
207+
bps.target_data[bps.output_offset++] = data;
208+
bps.target_checksum = ~(encoding_crc32(~bps.target_checksum, &data, 1));
209+
}
212210
break;
213211

214212
case TARGET_READ:
215213
while (length--)
216-
bps_write(&bps, bps_read(&bps));
214+
{
215+
uint8_t data = bps_read(&bps);
216+
bps.target_data[bps.output_offset++] = data;
217+
bps.target_checksum = ~(encoding_crc32(~bps.target_checksum, &data, 1));
218+
}
217219
break;
218220

219221
case SOURCE_COPY:
@@ -231,13 +233,21 @@ static enum patch_error bps_apply_patch(
231233
{
232234
bps.source_offset += offset;
233235
while (length--)
234-
bps_write(&bps, bps.source_data[bps.source_offset++]);
236+
{
237+
uint8_t data = bps.source_data[bps.source_offset++];
238+
bps.target_data[bps.output_offset++] = data;
239+
bps.target_checksum = ~(encoding_crc32(~bps.target_checksum, &data, 1));
240+
}
235241
}
236242
else
237243
{
238244
bps.target_offset += offset;
239245
while (length--)
240-
bps_write(&bps, bps.target_data[bps.target_offset++]);
246+
{
247+
uint8_t data = bps.target_data[bps.target_offset++];
248+
bps.target_data[bps.output_offset++] = data;
249+
bps.target_checksum = ~(encoding_crc32(~bps.target_checksum, &data, 1));
250+
}
241251
break;
242252
}
243253
break;

tasks/task_screenshot.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,10 @@ static bool screenshot_dump(
239239
screenshot_task_state_t *state = (screenshot_task_state_t*)
240240
calloc(1, sizeof(*state));
241241

242-
/* If fullpath is true, name_base already contains a
242+
if (!state)
243+
return false;
244+
245+
/* If fullpath is true, name_base already contains a
243246
* static path + filename to save the screenshot to. */
244247
if (fullpath)
245248
strlcpy(state->filename, name_base, sizeof(state->filename));
@@ -261,7 +264,7 @@ static bool screenshot_dump(
261264
#endif
262265
if (savestate)
263266
state->flags |= SS_TASK_FLAG_SILENCE;
264-
267+
265268
if (history_list_enable)
266269
state->flags |= SS_TASK_FLAG_HISTORY_LIST_ENABLE;
267270
state->pixel_format_type = pixel_format_type;
@@ -329,7 +332,7 @@ static bool screenshot_dump(
329332
}
330333
else
331334
{
332-
size_t len = strlcpy(state->shotname,
335+
size_t len = strlcpy(state->shotname,
333336
path_basename_nocompression(name_base),
334337
sizeof(state->shotname));
335338
strlcpy(state->shotname + len,
@@ -548,7 +551,7 @@ bool take_screenshot(
548551
bool ret = false;
549552
uint32_t runloop_flags = runloop_get_flags();
550553
settings_t *settings = config_get_ptr();
551-
video_driver_state_t *video_st = video_state_get_ptr();
554+
video_driver_state_t *video_st = video_state_get_ptr();
552555
bool video_gpu_screenshot = settings->bools.video_gpu_screenshot;
553556
bool supports_viewport_read = video_st->current_video->read_viewport
554557
&& (video_st->current_video->viewport_info);

0 commit comments

Comments
 (0)