From: Tim Duesterhus Date: Thu, 15 Apr 2021 16:40:06 +0000 (+0200) Subject: CLEANUP: sample: Use explicit return for successful `json_query`s X-Git-Tag: v2.4-dev17~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b9cdf1cb765d06ec9e0e6d099def245b330f12f;p=thirdparty%2Fhaproxy.git CLEANUP: sample: Use explicit return for successful `json_query`s Move the `return 1` into each of the cases, instead of relying on the single `return 1` at the bottom of the function. --- diff --git a/src/sample.c b/src/sample.c index 89c443757b..ed60631687 100644 --- a/src/sample.c +++ b/src/sample.c @@ -3739,26 +3739,30 @@ static int sample_conv_json_query(const struct arg *args, struct sample *smp, vo return 0; smp->data.type = SMP_T_SINT; + + return 1; } else { double double_val; - if (mjson_get_number(smp->data.u.str.area, smp->data.u.str.data, args[0].data.str.area, &double_val) == 0) { + if (mjson_get_number(smp->data.u.str.area, smp->data.u.str.data, args[0].data.str.area, &double_val) == 0) return 0; - } else { - trash->data = snprintf(trash->area,trash->size,"%g",double_val); - smp->data.u.str = *trash; - smp->data.type = SMP_T_STR; - } + + trash->data = snprintf(trash->area,trash->size,"%g",double_val); + smp->data.u.str = *trash; + smp->data.type = SMP_T_STR; + + return 1; } - break; case MJSON_TOK_TRUE: smp->data.type = SMP_T_BOOL; smp->data.u.sint = 1; - break; + + return 1; case MJSON_TOK_FALSE: smp->data.type = SMP_T_BOOL; smp->data.u.sint = 0; - break; + + return 1; case MJSON_TOK_STRING: { int len; @@ -3767,12 +3771,13 @@ static int sample_conv_json_query(const struct arg *args, struct sample *smp, vo if (len == -1) { /* invalid string */ return 0; - } else { - trash->data = len; - smp->data.u.str = *trash; - smp->data.type = SMP_T_STR; } - break; + + trash->data = len; + smp->data.u.str = *trash; + smp->data.type = SMP_T_STR; + + return 1; } case MJSON_TOK_NULL: case MJSON_TOK_ARRAY: @@ -3789,7 +3794,9 @@ static int sample_conv_json_query(const struct arg *args, struct sample *smp, vo */ return 0; } - return 1; + + my_unreachable(); + return 0; }