From 24f2c30678eec81095e8f5db977800c317e5ce53 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 4 Jan 2023 10:29:32 +0100 Subject: [PATCH] drivers: regulator: shell: fix isdigit() usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ISO/IEC 9899:1999 (C Standard), ยง7.4 Character handling : In all cases the argument is an int, the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF. If the argument has any other value, the behavior is undefined. So add a cast to unsigned char to make sure we do not trigger UB. Signed-off-by: Gerard Marull-Paretas --- drivers/regulator/regulator_shell.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/regulator_shell.c b/drivers/regulator/regulator_shell.c index 2f17a712521..2e453b9701d 100644 --- a/drivers/regulator/regulator_shell.c +++ b/drivers/regulator/regulator_shell.c @@ -35,7 +35,7 @@ static int strtomicro(char *inp, char units, int32_t *val) } else if ((len > 2) && (inp[len - 2] == 'm')) { mult = 1000; end = len - 3; - } else if (isdigit(inp[len - 2]) > 0) { + } else if (isdigit((unsigned char)inp[len - 2]) > 0) { mult = 1000000; end = len - 2; } else { @@ -55,7 +55,7 @@ static int strtomicro(char *inp, char units, int32_t *val) /* numeric part */ *val = 0; for (size_t i = start; i <= end; i++) { - if (isdigit(inp[i]) > 0) { + if (isdigit((unsigned char)inp[i]) > 0) { *val = *val * 10 / decdiv + (int32_t)(inp[i] - '0') * mult / decdiv; } else if (inp[i] == '.') {