From f5daea22738cff9d6c9d0a1938519803e3774073 Mon Sep 17 00:00:00 2001 From: Havard Eidnes Date: Wed, 24 May 2023 22:57:37 +0000 Subject: [PATCH] strnatcmp.c: ensure correct value range for isdigit() argument. The valid values to pass to `isdigit()` is the values represented by `unsigned char` and the value of EOF (usually -1). Other values such as the other negative `signed char` values may invoke undefined behaviour. Fix this by casting the argument to `isdigit()` to `unsigned char`. Found by building on NetBSD/macppc with -Wchar-subscripts turned on. --- src/base/strnatcmp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base/strnatcmp.c b/src/base/strnatcmp.c index 2a2d2e9f..67731641 100644 --- a/src/base/strnatcmp.c +++ b/src/base/strnatcmp.c @@ -275,13 +275,13 @@ int ipv4cmp(int a_len, nat_char const *a, } for (; ai < a_len; ai++) { - if (!isdigit(a[ai]) || a[ai] != '.') { + if (!isdigit((unsigned char)a[ai]) || a[ai] != '.') { return 0; } } for (; bi < b_len; bi++) { - if (!isdigit(b[bi]) || b[bi] != '.') { + if (!isdigit((unsigned char)b[bi]) || b[bi] != '.') { return 0; } }