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.
This commit is contained in:
Havard Eidnes 2023-05-24 22:57:37 +00:00
parent 34f026e444
commit f5daea2273

View File

@ -275,13 +275,13 @@ int ipv4cmp(int a_len, nat_char const *a,
} }
for (; ai < a_len; ai++) { for (; ai < a_len; ai++) {
if (!isdigit(a[ai]) || a[ai] != '.') { if (!isdigit((unsigned char)a[ai]) || a[ai] != '.') {
return 0; return 0;
} }
} }
for (; bi < b_len; bi++) { for (; bi < b_len; bi++) {
if (!isdigit(b[bi]) || b[bi] != '.') { if (!isdigit((unsigned char)b[bi]) || b[bi] != '.') {
return 0; return 0;
} }
} }