Silence some Coverity warnings

This commit is contained in:
twinaphex 2018-04-12 21:39:31 +02:00
parent 6e4cf412f0
commit 6761ec471d
4 changed files with 72 additions and 70 deletions

View file

@ -1334,10 +1334,8 @@ static int cheevos_new_lboard(cheevos_readud_t *ud)
if (!ldb || !ud) if (!ldb || !ud)
return -1; return -1;
lboard = ldb + ud->lboard_count++;
if (!lboard) lboard = ldb + ud->lboard_count++;
return -1;
lboard->id = (unsigned)strtol(ud->id.string, NULL, 10); lboard->id = (unsigned)strtol(ud->id.string, NULL, 10);
lboard->format = cheevos_parse_format(&ud->format); lboard->format = cheevos_parse_format(&ud->format);

View file

@ -39,7 +39,7 @@ static unsigned old_libretro_device[MAX_USERS];
**/ **/
bool input_remapping_load_file(void *data, const char *path) bool input_remapping_load_file(void *data, const char *path)
{ {
unsigned i, j; unsigned i, j, k;
config_file_t *conf = (config_file_t*)data; config_file_t *conf = (config_file_t*)data;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr(); global_t *global = global_get_ptr();
@ -54,9 +54,9 @@ bool input_remapping_load_file(void *data, const char *path)
for (i = 0; i < MAX_USERS; i++) for (i = 0; i < MAX_USERS; i++)
{ {
char s1[64], s2[64], s3[64]; char s1[64], s2[64], s3[64];
char btn_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}}; char btn_ident[RARCH_FIRST_CUSTOM_BIND][128] = {{0}};
char key_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}}; char key_ident[RARCH_FIRST_CUSTOM_BIND][128] = {{0}};
char stk_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}}; char stk_ident[8][128] = {{0}};
char key_strings[RARCH_FIRST_CUSTOM_BIND + 8][128] = { char key_strings[RARCH_FIRST_CUSTOM_BIND + 8][128] = {
"b", "y", "select", "start", "b", "y", "select", "start",
@ -75,7 +75,9 @@ bool input_remapping_load_file(void *data, const char *path)
snprintf(s2, sizeof(s2), "input_player%u_key", i + 1); snprintf(s2, sizeof(s2), "input_player%u_key", i + 1);
snprintf(s3, sizeof(s3), "input_player%u_stk", i + 1); snprintf(s3, sizeof(s3), "input_player%u_stk", i + 1);
for (j = 0; j < RARCH_FIRST_CUSTOM_BIND; j++) for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 8; j++)
{
if (j < RARCH_FIRST_CUSTOM_BIND)
{ {
int btn_remap = -1; int btn_remap = -1;
int key_remap = -1; int key_remap = -1;
@ -98,30 +100,31 @@ bool input_remapping_load_file(void *data, const char *path)
else else
settings->uints.input_keymapper_ids[i][j] = RETROK_UNKNOWN; settings->uints.input_keymapper_ids[i][j] = RETROK_UNKNOWN;
} }
else
for (j = RARCH_FIRST_CUSTOM_BIND; j < RARCH_FIRST_CUSTOM_BIND + 8; j++)
{ {
int stk_remap = -1; int stk_remap = -1;
k = j - RARCH_FIRST_CUSTOM_BIND;
fill_pathname_join_delim(stk_ident[j], s3, fill_pathname_join_delim(stk_ident[k], s3,
key_strings[j], '$', sizeof(stk_ident[j])); key_strings[j], '$', sizeof(stk_ident[k]));
snprintf(stk_ident[j], snprintf(stk_ident[k],
sizeof(stk_ident[j]), sizeof(stk_ident[k]),
"%s_%s", "%s_%s",
s3, s3,
key_strings[j]); key_strings[j]);
/* RARCH_LOG("pre_ident: %s:%d\n", stk_ident[j], settings->uints.input_remap_ids[i][j]); */ /* RARCH_LOG("pre_ident: %s:%d\n", stk_ident[j], settings->uints.input_remap_ids[i][j]); */
if (config_get_int(conf, stk_ident[j], &stk_remap) && stk_remap != -1) if (config_get_int(conf, stk_ident[k], &stk_remap) && stk_remap != -1)
settings->uints.input_remap_ids[i][j] = stk_remap; settings->uints.input_remap_ids[i][j] = stk_remap;
else if (config_get_int(conf, stk_ident[j], &stk_remap) && stk_remap == -1) else if (config_get_int(conf, stk_ident[k], &stk_remap) && stk_remap == -1)
settings->uints.input_remap_ids[i][j] = RARCH_UNMAPPED; settings->uints.input_remap_ids[i][j] = RARCH_UNMAPPED;
/* else do nothing, important */ /* else do nothing, important */
/*RARCH_LOG("stk_ident: %s:%d\n", stk_ident[j], settings->uints.input_remap_ids[i][j]);*/ /*RARCH_LOG("stk_ident: %s:%d\n", stk_ident[j], settings->uints.input_remap_ids[i][j]);*/
} }
}
snprintf(s1, sizeof(s1), "input_player%u_analog_dpad_mode", i + 1); snprintf(s1, sizeof(s1), "input_player%u_analog_dpad_mode", i + 1);
CONFIG_GET_INT_BASE(conf, settings, uints.input_analog_dpad_mode[i], s1); CONFIG_GET_INT_BASE(conf, settings, uints.input_analog_dpad_mode[i], s1);
@ -146,7 +149,7 @@ bool input_remapping_load_file(void *data, const char *path)
bool input_remapping_save_file(const char *path) bool input_remapping_save_file(const char *path)
{ {
bool ret; bool ret;
unsigned i, j; unsigned i, j, k;
size_t path_size = PATH_MAX_LENGTH * sizeof(char); size_t path_size = PATH_MAX_LENGTH * sizeof(char);
char *buf = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char *buf = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
char *remap_file = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char *remap_file = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
@ -178,9 +181,9 @@ bool input_remapping_save_file(const char *path)
for (i = 0; i < max_users; i++) for (i = 0; i < max_users; i++)
{ {
char s1[64], s2[64], s3[64]; char s1[64], s2[64], s3[64];
char btn_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}}; char btn_ident[RARCH_FIRST_CUSTOM_BIND][128] = {{0}};
char key_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}}; char key_ident[RARCH_FIRST_CUSTOM_BIND][128] = {{0}};
char stk_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}}; char stk_ident[8][128] = {{0}};
char key_strings[RARCH_FIRST_CUSTOM_BIND + 8][128] = { char key_strings[RARCH_FIRST_CUSTOM_BIND + 8][128] = {
"b", "y", "select", "start", "b", "y", "select", "start",
@ -196,6 +199,9 @@ bool input_remapping_save_file(const char *path)
snprintf(s3, sizeof(s1), "input_player%u_stk", i + 1); snprintf(s3, sizeof(s1), "input_player%u_stk", i + 1);
for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 8; j++) for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 8; j++)
{
if(j < RARCH_FIRST_CUSTOM_BIND)
{ {
fill_pathname_join_delim(btn_ident[j], s1, fill_pathname_join_delim(btn_ident[j], s1,
key_strings[j], '_', sizeof(btn_ident[j])); key_strings[j], '_', sizeof(btn_ident[j]));
@ -203,8 +209,6 @@ bool input_remapping_save_file(const char *path)
key_strings[j], '_', sizeof(btn_ident[j])); key_strings[j], '_', sizeof(btn_ident[j]));
/* only save values that have been modified */ /* only save values that have been modified */
if(j < RARCH_FIRST_CUSTOM_BIND)
{
if(settings->uints.input_remap_ids[i][j] != j && if(settings->uints.input_remap_ids[i][j] != j &&
settings->uints.input_remap_ids[i][j] != RARCH_UNMAPPED) settings->uints.input_remap_ids[i][j] != RARCH_UNMAPPED)
config_set_int(conf, btn_ident[j], settings->uints.input_remap_ids[i][j]); config_set_int(conf, btn_ident[j], settings->uints.input_remap_ids[i][j]);
@ -221,15 +225,16 @@ bool input_remapping_save_file(const char *path)
} }
else else
{ {
fill_pathname_join_delim(stk_ident[j], s3, k = j - RARCH_FIRST_CUSTOM_BIND;
key_strings[j], '_', sizeof(stk_ident[j])); fill_pathname_join_delim(stk_ident[k], s3,
key_strings[j], '_', sizeof(stk_ident[k]));
if(settings->uints.input_remap_ids[i][j] != j && if(settings->uints.input_remap_ids[i][j] != j &&
settings->uints.input_remap_ids[i][j] != RARCH_UNMAPPED) settings->uints.input_remap_ids[i][j] != RARCH_UNMAPPED)
config_set_int(conf, stk_ident[j], config_set_int(conf, stk_ident[k],
settings->uints.input_remap_ids[i][j]); settings->uints.input_remap_ids[i][j]);
else if(settings->uints.input_remap_ids[i][j] != j && else if(settings->uints.input_remap_ids[i][j] != j &&
settings->uints.input_remap_ids[i][j] == RARCH_UNMAPPED) settings->uints.input_remap_ids[i][j] == RARCH_UNMAPPED)
config_set_int(conf, stk_ident[j], config_set_int(conf, stk_ident[k],
-1); -1);
else else
config_unset(conf,btn_ident[j]); config_unset(conf,btn_ident[j]);
@ -289,15 +294,16 @@ void input_remapping_set_defaults(bool deinit)
for (i = 0; i < MAX_USERS; i++) for (i = 0; i < MAX_USERS; i++)
{ {
for (j = 0; j < RARCH_FIRST_CUSTOM_BIND; j++) for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 8; j++)
{
if (j < RARCH_FIRST_CUSTOM_BIND)
{ {
const struct retro_keybind *keybind = &input_config_binds[i][j]; const struct retro_keybind *keybind = &input_config_binds[i][j];
if (keybind) if (keybind)
settings->uints.input_remap_ids[i][j] = keybind->id; settings->uints.input_remap_ids[i][j] = keybind->id;
settings->uints.input_keymapper_ids[i][j] = RETROK_UNKNOWN; settings->uints.input_keymapper_ids[i][j] = RETROK_UNKNOWN;
} }
for (j = RARCH_FIRST_CUSTOM_BIND; j < RARCH_FIRST_CUSTOM_BIND + 8; j++) else
{
settings->uints.input_remap_ids[i][j] = j; settings->uints.input_remap_ids[i][j] = j;
} }

View file

@ -292,6 +292,7 @@ static void merge_analog_part(netplay_t *netplay,
} }
if (share_mode == NETPLAY_SHARE_ANALOG_AVERAGE) if (share_mode == NETPLAY_SHARE_ANALOG_AVERAGE)
if (client_count > 0) /* Prevent potential divide by zero */
value /= client_count; value /= client_count;
resstate->data[word] |= ((uint32_t) (uint16_t) value) << bit; resstate->data[word] |= ((uint32_t) (uint16_t) value) << bit;

View file

@ -327,13 +327,10 @@ static bool task_overlay_resolve_targets(struct overlay *ol,
unsigned i; unsigned i;
struct overlay *current = (struct overlay*)&ol[idx]; struct overlay *current = (struct overlay*)&ol[idx];
if (!current)
return false;
for (i = 0; i < current->size; i++) for (i = 0; i < current->size; i++)
{ {
struct overlay_desc *desc = (struct overlay_desc*)&current->descs[i]; struct overlay_desc *desc = (struct overlay_desc*)&current->descs[i];
const char *next = desc ? desc->next_index_name : NULL; const char *next = desc->next_index_name;
ssize_t next_idx = (idx + 1) & size; ssize_t next_idx = (idx + 1) & size;
if (!string_is_empty(next)) if (!string_is_empty(next))