From bf8f7b444bdd92240b67bb33a4a81a3dc82083ac Mon Sep 17 00:00:00 2001 From: leiradel Date: Thu, 7 Dec 2017 23:48:03 +0000 Subject: [PATCH 1/3] Fixed cheevos_expr_value to be C89 compliant --- cheevos/cheevos.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 87517d6164..c11984a229 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -1859,13 +1859,26 @@ static int cheevos_expr_value(cheevos_expr_t* expr) /* Separate possible values with '$' operator, submit the largest */ unsigned current_value = 0; /* TODO/FIXME - variable length forbidden in C89 - rewrite this! */ - int values[expr->compare_count]; + int values[16]; + + if (expr->compare_count >= sizeof(values) / sizeof(values[0])) + { + RARCH_ERR("[CHEEVOS]: too many values in the leaderboard expression: %u\n", expr->compare_count); + return 0; + } memset(values, 0, sizeof values); for (i = expr->count; i != 0; i--, term++) { + if (current_value >= sizeof(values) / sizeof(values[0])) + { + RARCH_ERR("[CHEEVOS]: too many values in the leaderboard expression: %u\n", current_value); + return 0; + } + values[current_value] += cheevos_var_get_value(&term->var) * term->multiplier; + if (term->compare_next) current_value++; } @@ -1880,7 +1893,8 @@ static int cheevos_expr_value(cheevos_expr_t* expr) return maximum; } - else return values[0]; + else + return values[0]; } static void cheevos_make_lboard_url(const cheevos_leaderboard_t *lboard, From c53d3d35b8962962b47ce86f22ab7b095cef5b3c Mon Sep 17 00:00:00 2001 From: leiradel Date: Thu, 7 Dec 2017 23:51:15 +0000 Subject: [PATCH 2/3] Removed TODO comment --- cheevos/cheevos.c | 1 - 1 file changed, 1 deletion(-) diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index c11984a229..5a7687dc64 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -1858,7 +1858,6 @@ static int cheevos_expr_value(cheevos_expr_t* expr) unsigned i; /* Separate possible values with '$' operator, submit the largest */ unsigned current_value = 0; - /* TODO/FIXME - variable length forbidden in C89 - rewrite this! */ int values[16]; if (expr->compare_count >= sizeof(values) / sizeof(values[0])) From 8c1e3e5d5b5ae80932b96bfc502d8db9e46ff8aa Mon Sep 17 00:00:00 2001 From: leiradel Date: Fri, 8 Dec 2017 00:08:16 +0000 Subject: [PATCH 3/3] Fixed CXX_BUILD --- cheevos/cheevos.c | 6 +++--- cheevos/cheevos.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 5a7687dc64..0b9a1ea075 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -258,7 +258,7 @@ typedef struct typedef struct { - int console_id; + cheevos_console_t console_id; bool core_supports; bool addrs_patched; int add_buffer; @@ -276,7 +276,7 @@ typedef struct static cheevos_locals_t cheevos_locals = { - /* console_id */ 0, + /* console_id */ CHEEVOS_CONSOLE_NONE, /* core_supports */ true, /* addrs_patched */ false, /* add_buffer */ 0, @@ -1385,7 +1385,7 @@ static int cheevos_read__json_number(void *userdata, } else if (ud->is_console_id) { - cheevos_locals.console_id = (int)strtol(number, NULL, 10); + cheevos_locals.console_id = (cheevos_console_t)strtol(number, NULL, 10); ud->is_console_id = 0; } diff --git a/cheevos/cheevos.h b/cheevos/cheevos.h index cf2526e504..ed1baae311 100644 --- a/cheevos/cheevos.h +++ b/cheevos/cheevos.h @@ -47,6 +47,7 @@ typedef struct cheevos_ctx_desc typedef enum { + CHEEVOS_CONSOLE_NONE = 0, /* Don't change those, the values match the console IDs * at retroachievements.org. */ CHEEVOS_CONSOLE_MEGA_DRIVE = 1,