Prevent more static code analysis warnings

This commit is contained in:
twinaphex 2020-06-29 21:01:30 +02:00
parent b93c3b36ed
commit 3239576ba1

View File

@ -3487,15 +3487,17 @@ static void menu_input_key_bind_poll_bind_state(
{ {
unsigned b; unsigned b;
rarch_joypad_info_t joypad_info; rarch_joypad_info_t joypad_info;
input_driver_t *input_ptr = p_rarch->current_input; input_driver_t *current_input = p_rarch->current_input;
void *input_data = p_rarch->current_input_data; void *input_data = p_rarch->current_input_data;
unsigned port = state->port; unsigned port = state->port;
const input_device_driver_t *joypad = NULL; const input_device_driver_t *joypad = NULL;
const input_device_driver_t *sec_joypad = const input_device_driver_t *sec_joypad =
input_driver_get_sec_joypad_driver(); input_driver_get_sec_joypad_driver();
if (p_rarch->current_input->get_joypad_driver) if ( current_input
joypad = p_rarch->current_input->get_joypad_driver(p_rarch->current_input_data); && current_input->get_joypad_driver)
joypad =
current_input->get_joypad_driver(input_data);
memset(state->state, 0, sizeof(state->state)); memset(state->state, 0, sizeof(state->state));
@ -3508,7 +3510,9 @@ static void menu_input_key_bind_poll_bind_state(
joypad_info.auto_binds = NULL; joypad_info.auto_binds = NULL;
joypad_info.axis_threshold = 0.0f; joypad_info.axis_threshold = 0.0f;
state->skip = timed_out || input_ptr->input_state(input_data, state->skip =
timed_out ||
current_input->input_state(input_data,
&joypad_info, &joypad_info,
NULL, NULL,
0, RETRO_DEVICE_KEYBOARD, 0, RETROK_RETURN); 0, RETRO_DEVICE_KEYBOARD, 0, RETROK_RETURN);
@ -4911,7 +4915,7 @@ struct string_list *menu_entry_enum_values(uint32_t i)
menu_file_list_cbs_t *cbs = selection_buf ? menu_file_list_cbs_t *cbs = selection_buf ?
(menu_file_list_cbs_t*)selection_buf->list[i].actiondata : NULL; (menu_file_list_cbs_t*)selection_buf->list[i].actiondata : NULL;
rarch_setting_t *setting = cbs ? cbs->setting : NULL; rarch_setting_t *setting = cbs ? cbs->setting : NULL;
const char *values = setting->values; const char *values = setting ? setting->values : NULL;
if (!values) if (!values)
return NULL; return NULL;
@ -5003,7 +5007,7 @@ bool menu_entry_pathdir_allow_empty(uint32_t i)
menu_file_list_cbs_t *cbs = selection_buf ? menu_file_list_cbs_t *cbs = selection_buf ?
(menu_file_list_cbs_t*)selection_buf->list[i].actiondata : NULL; (menu_file_list_cbs_t*)selection_buf->list[i].actiondata : NULL;
rarch_setting_t *setting = cbs ? cbs->setting : NULL; rarch_setting_t *setting = cbs ? cbs->setting : NULL;
uint64_t flags = setting->flags; uint64_t flags = setting ? setting->flags : 0;
return flags & SD_FLAG_ALLOW_EMPTY; return flags & SD_FLAG_ALLOW_EMPTY;
} }
@ -5016,7 +5020,7 @@ uint32_t menu_entry_pathdir_for_directory(uint32_t i)
menu_file_list_cbs_t *cbs = selection_buf ? menu_file_list_cbs_t *cbs = selection_buf ?
(menu_file_list_cbs_t*)selection_buf->list[i].actiondata : NULL; (menu_file_list_cbs_t*)selection_buf->list[i].actiondata : NULL;
rarch_setting_t *setting = cbs ? cbs->setting : NULL; rarch_setting_t *setting = cbs ? cbs->setting : NULL;
uint64_t flags = setting->flags; uint64_t flags = setting ? setting->flags : 0;
return flags & SD_FLAG_PATH_DIR; return flags & SD_FLAG_PATH_DIR;
} }
@ -5029,7 +5033,7 @@ void menu_entry_pathdir_extensions(uint32_t i, char *s, size_t len)
menu_file_list_cbs_t *cbs = selection_buf ? menu_file_list_cbs_t *cbs = selection_buf ?
(menu_file_list_cbs_t*)selection_buf->list[i].actiondata : NULL; (menu_file_list_cbs_t*)selection_buf->list[i].actiondata : NULL;
rarch_setting_t *setting = cbs ? cbs->setting : NULL; rarch_setting_t *setting = cbs ? cbs->setting : NULL;
const char *values = setting->values; const char *values = setting ? setting->values : NULL;
if (!values) if (!values)
return; return;
@ -5081,7 +5085,7 @@ uint32_t menu_entry_num_has_range(uint32_t i)
menu_file_list_cbs_t *cbs = selection_buf ? menu_file_list_cbs_t *cbs = selection_buf ?
(menu_file_list_cbs_t*)selection_buf->list[i].actiondata : NULL; (menu_file_list_cbs_t*)selection_buf->list[i].actiondata : NULL;
rarch_setting_t *setting = cbs ? cbs->setting : NULL; rarch_setting_t *setting = cbs ? cbs->setting : NULL;
uint64_t flags = setting->flags; uint64_t flags = setting ? setting->flags : 0;
return (flags & SD_FLAG_HAS_RANGE); return (flags & SD_FLAG_HAS_RANGE);
} }
@ -5106,7 +5110,7 @@ float menu_entry_num_max(uint32_t i)
menu_file_list_cbs_t *cbs = selection_buf ? menu_file_list_cbs_t *cbs = selection_buf ?
(menu_file_list_cbs_t*)selection_buf->list[i].actiondata : NULL; (menu_file_list_cbs_t*)selection_buf->list[i].actiondata : NULL;
rarch_setting_t *setting = cbs ? cbs->setting : NULL; rarch_setting_t *setting = cbs ? cbs->setting : NULL;
double max = setting->max; double max = setting ? setting->max : 0.00f;
return (float)max; return (float)max;
} }
@ -8184,12 +8188,15 @@ void menu_shader_manager_clear_pass_scale(struct video_shader *shader,
void menu_shader_manager_clear_pass_path(struct video_shader *shader, void menu_shader_manager_clear_pass_path(struct video_shader *shader,
unsigned i) unsigned i)
{ {
struct video_shader_pass *shader_pass = shader ? struct video_shader_pass
&shader->pass[i] : NULL; *shader_pass = shader
? &shader->pass[i]
: NULL;
if (shader_pass) if (shader_pass)
*shader_pass->source.path = '\0'; *shader_pass->source.path = '\0';
if (shader)
shader->modified = true; shader->modified = true;
} }
@ -9562,9 +9569,13 @@ static int16_t input_state_net(unsigned port, unsigned device,
{ {
struct rarch_state *p_rarch = &rarch_st; struct rarch_state *p_rarch = &rarch_st;
netplay_t *netplay = p_rarch->netplay_data; netplay_t *netplay = p_rarch->netplay_data;
if (netplay && netplay_is_alive(netplay)) if (netplay)
{
if (netplay_is_alive(netplay))
return netplay_input_state(netplay, port, device, idx, id); return netplay_input_state(netplay, port, device, idx, id);
return netplay->cbs.state_cb(port, device, idx, id); return netplay->cbs.state_cb(port, device, idx, id);
}
return 0;
} }
/* ^^^ Netplay polling callbacks */ /* ^^^ Netplay polling callbacks */
@ -12938,13 +12949,14 @@ static bool call_auto_translate_task(
} }
else /* Speech or Narrator Mode */ else /* Speech or Narrator Mode */
{ {
retro_task_t *t = NULL; int* mode = NULL;
int* mode = (int*)malloc(sizeof(int)); retro_task_t *t = task_init();
*mode = ai_service_mode;
t = task_init();
if (!t) if (!t)
return false; return false;
mode = (int*)malloc(sizeof(int));
*mode = ai_service_mode;
t->handler = task_auto_translate_handler; t->handler = task_auto_translate_handler;
t->user_data = mode; t->user_data = mode;
t->mute = true; t->mute = true;
@ -13936,7 +13948,7 @@ static bool run_translation_service(
#endif #endif
#endif #endif
json_length+=state_son_length; json_length += state_son_length;
} }
json_buffer = (char*)malloc(json_length); json_buffer = (char*)malloc(json_length);
@ -13950,19 +13962,24 @@ static bool run_translation_service(
curr_length = 11 + out_length + 1; curr_length = 11 + out_length + 1;
/* State data */ /* State data */
memcpy(json_buffer+curr_length, state_son, state_son_length*sizeof(uint8_t)); memcpy(json_buffer + curr_length, state_son,
state_son_length * sizeof(uint8_t));
curr_length += state_son_length; curr_length += state_son_length;
/* System Label */ /* System Label */
if (rf3) if (rf3)
{ {
size_t system_label_len = strlen(system_label); size_t system_label_len = strlen(system_label);
memcpy(json_buffer + curr_length, (const void*)rf3, (15 + system_label_len) * sizeof(uint8_t)); memcpy(json_buffer + curr_length,
(const void*)rf3,
(15 + system_label_len) * sizeof(uint8_t));
curr_length += 15 + system_label_len; curr_length += 15 + system_label_len;
} }
else else
{ {
memcpy(json_buffer + curr_length, (const void*)rf2, 3 * sizeof(uint8_t)); memcpy(json_buffer + curr_length,
(const void*)rf2,
3 * sizeof(uint8_t));
curr_length += 3; curr_length += 3;
} }
@ -13996,7 +14013,8 @@ static bool run_translation_service(
sizeof(temp_string), sizeof(temp_string),
"%csource_lang=%s", separator, lang_source); "%csource_lang=%s", separator, lang_source);
separator = '&'; separator = '&';
strlcat(new_ai_service_url, temp_string, sizeof(new_ai_service_url)); strlcat(new_ai_service_url,
temp_string, sizeof(new_ai_service_url));
} }
} }
@ -25846,7 +25864,8 @@ static const input_device_driver_t *input_joypad_init_first(void *data)
for (i = 0; joypad_drivers[i]; i++) for (i = 0; joypad_drivers[i]; i++)
{ {
if (joypad_drivers[i]->init(data)) if ( joypad_drivers[i] &&
joypad_drivers[i]->init(data))
{ {
RARCH_LOG("[Joypad]: Found joypad driver: \"%s\".\n", RARCH_LOG("[Joypad]: Found joypad driver: \"%s\".\n",
joypad_drivers[i]->ident); joypad_drivers[i]->ident);
@ -26796,6 +26815,8 @@ static void input_config_parse_joy_button(
config_file_t *conf, const char *prefix, config_file_t *conf, const char *prefix,
const char *btn, struct retro_keybind *bind) const char *btn, struct retro_keybind *bind)
{ {
if (bind)
{
char str[256]; char str[256];
char tmp[64]; char tmp[64];
char key[64]; char key[64];
@ -26825,7 +26846,7 @@ static void input_config_parse_joy_button(
if (*btn == 'h') if (*btn == 'h')
{ {
const char *str = btn + 1; const char *str = btn + 1;
if (bind && str && isdigit((int)*str)) if (str && isdigit((int)*str))
parse_hat(bind, str); parse_hat(bind, str);
} }
else else
@ -26833,7 +26854,7 @@ static void input_config_parse_joy_button(
} }
} }
if (bind && config_get_string(conf, key_label, &tmp_a)) if (config_get_string(conf, key_label, &tmp_a))
{ {
if (!string_is_empty(bind->joykey_label)) if (!string_is_empty(bind->joykey_label))
free(bind->joykey_label); free(bind->joykey_label);
@ -26841,12 +26862,15 @@ static void input_config_parse_joy_button(
bind->joykey_label = strdup(tmp_a); bind->joykey_label = strdup(tmp_a);
free(tmp_a); free(tmp_a);
} }
}
} }
static void input_config_parse_joy_axis( static void input_config_parse_joy_axis(
config_file_t *conf, const char *prefix, config_file_t *conf, const char *prefix,
const char *axis, struct retro_keybind *bind) const char *axis, struct retro_keybind *bind)
{ {
if (bind)
{
char str[256]; char str[256];
char tmp[64]; char tmp[64];
char key[64]; char key[64];
@ -26891,12 +26915,15 @@ static void input_config_parse_joy_axis(
bind->joyaxis_label = strdup(tmp_a); bind->joyaxis_label = strdup(tmp_a);
free(tmp_a); free(tmp_a);
} }
}
} }
static void input_config_parse_mouse_button( static void input_config_parse_mouse_button(
config_file_t *conf, const char *prefix, config_file_t *conf, const char *prefix,
const char *btn, struct retro_keybind *bind) const char *btn, struct retro_keybind *bind)
{ {
if (bind)
{
int val; int val;
char str[256]; char str[256];
char tmp[64]; char tmp[64];
@ -26909,7 +26936,7 @@ static void input_config_parse_mouse_button(
fill_pathname_join_delim(key, str, fill_pathname_join_delim(key, str,
"mbtn", '_', sizeof(key)); "mbtn", '_', sizeof(key));
if (bind && config_get_array(conf, key, tmp, sizeof(tmp))) if (config_get_array(conf, key, tmp, sizeof(tmp)))
{ {
bind->mbutton = NO_BTN; bind->mbutton = NO_BTN;
@ -26959,6 +26986,7 @@ static void input_config_parse_mouse_button(
} }
} }
} }
}
} }
static void input_config_get_bind_string_joykey( static void input_config_get_bind_string_joykey(
@ -26966,8 +26994,12 @@ static void input_config_get_bind_string_joykey(
char *buf, const char *prefix, char *buf, const char *prefix,
const struct retro_keybind *bind, size_t size) const struct retro_keybind *bind, size_t size)
{ {
settings_t *settings = p_rarch->configuration_settings; if (bind)
bool label_show = settings->bools.input_descriptor_label_show; {
settings_t *settings =
p_rarch->configuration_settings;
bool label_show =
settings->bools.input_descriptor_label_show;
if (GET_HAT_DIR(bind->joykey)) if (GET_HAT_DIR(bind->joykey))
{ {
@ -27011,6 +27043,7 @@ static void input_config_get_bind_string_joykey(
snprintf(buf, size, "%s%u (%s)", prefix, (unsigned)bind->joykey, snprintf(buf, size, "%s%u (%s)", prefix, (unsigned)bind->joykey,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE)); msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE));
} }
}
} }
static void input_config_get_bind_string_joyaxis( static void input_config_get_bind_string_joyaxis(
@ -27018,8 +27051,12 @@ static void input_config_get_bind_string_joyaxis(
char *buf, const char *prefix, char *buf, const char *prefix,
const struct retro_keybind *bind, size_t size) const struct retro_keybind *bind, size_t size)
{ {
settings_t *settings = p_rarch->configuration_settings; if (bind)
bool input_descriptor_label_show = settings->bools.input_descriptor_label_show; {
settings_t *settings =
p_rarch->configuration_settings;
bool input_descriptor_label_show =
settings->bools.input_descriptor_label_show;
if (bind->joyaxis_label && if (bind->joyaxis_label &&
!string_is_empty(bind->joyaxis_label) !string_is_empty(bind->joyaxis_label)
@ -27043,10 +27080,13 @@ static void input_config_get_bind_string_joyaxis(
snprintf(buf, size, "%s%c%u (%s)", prefix, dir, axis, snprintf(buf, size, "%s%c%u (%s)", prefix, dir, axis,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE)); msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE));
} }
}
} }
void input_config_get_bind_string(char *buf, const struct retro_keybind *bind, void input_config_get_bind_string(char *buf,
const struct retro_keybind *auto_bind, size_t size) const struct retro_keybind *bind,
const struct retro_keybind *auto_bind,
size_t size)
{ {
int delim = 0; int delim = 0;
struct rarch_state *p_rarch = &rarch_st; struct rarch_state *p_rarch = &rarch_st;