From bf8f7b444bdd92240b67bb33a4a81a3dc82083ac Mon Sep 17 00:00:00 2001 From: leiradel Date: Thu, 7 Dec 2017 23:48:03 +0000 Subject: [PATCH] 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,