From be03ae39eb6ef52c2a262e7b1e26a553b8e09d78 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 23 Apr 2019 10:03:34 -0400 Subject: [PATCH] cli: Adjust integer range check, replace magic numbers with constants The value (1ULL << 63) - 1), used for checking that integer values are within range, actually mean INT64_MAX, so use that instead. Also, the negative case is not quite right: the value -(INT64_MAX + 1), -9223372036854775808, is within the range of a signed 64-bits number (assuming two's complement), but is not accepted right now. Adjust the check so it accepts that value. I tested this patch manually: we accept -9223372036854775808 but reject -9223372036854775809. Signed-off-by: Simon Marchi --- cli/babeltrace-cfg-cli-args.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/babeltrace-cfg-cli-args.c b/cli/babeltrace-cfg-cli-args.c index a86d1096e..b71b70f53 100644 --- a/cli/babeltrace-cfg-cli-args.c +++ b/cli/babeltrace-cfg-cli-args.c @@ -198,7 +198,7 @@ bt_value *ini_parse_neg_number(struct ini_parsing_state *state) /* Negative integer */ uint64_t int_val = state->scanner->value.v_int64; - if (int_val > (1ULL << 63) - 1) { + if (int_val > (((uint64_t) INT64_MAX) + 1)) { g_string_append_printf(state->ini_error, "Integer value -%" PRIu64 " is outside the range of a 64-bit signed integer\n", int_val); @@ -244,7 +244,7 @@ bt_value *ini_parse_value(struct ini_parsing_state *state) /* Positive integer */ uint64_t int_val = state->scanner->value.v_int64; - if (int_val > (1ULL << 63) - 1) { + if (int_val > INT64_MAX) { g_string_append_printf(state->ini_error, "Integer value %" PRIu64 " is outside the range of a 64-bit signed integer\n", int_val); -- 2.34.1