Skip to contentSkip to conversation

util/cutils: Use qemu_isdigit() instead of isdigit()

PATCH In review Thomas Huth 2 participants 2 messages Sep 10

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 util/cutils: Use qemu_isdigit() instead of isdigit()

When building QEMU for NetBSD ("make vm-build-netbsd"), the compiler complains:

In file included from /usr/include/ctype.h:100,

                 from ../src/include/qemu/osdep.h:123,
                 from ../src/util/cutils.c:25:

../src/util/cutils.c: In function 'do_strtosz':
../src/util/cutils.c:245:61: warning: array subscript has type 'char' [-Wchar-subscripts]
245 | if (retval == 0 && *endptr == '.' && !isdigit(endptr[1])) {

isdigit() should not be used with plain "char" variables since these can be signed and isdigit() could be implemented as a macro that uses its parameter to index into an array. Use our wrapper qemu_isdigit() to fix this problem.

---
 util/cutils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
util/cutils.c +1 -1
index 96c80d4d429..91ddadfd15a 100644
@@ -242,7 +242,7 @@ static int do_strtosz(const char *nptr, const char **end,
          */
         double fraction = 0.0;
 
-        if (retval == 0 && *endptr == '.' && !isdigit(endptr[1])) {
+        if (retval == 0 && *endptr == '.' && !qemu_isdigit(endptr[1])) {
             /* If we got here, we parsed at least one digit already. */
             endptr++;
         } else {
Signature · 1 line
2.55.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Thomas Huth

When building QEMU for NetBSD ("make vm-build-netbsd"), the compiler complains:

In file included from /usr/include/ctype.h:100,

                 from ../src/include/qemu/osdep.h:123,
                 from ../src/util/cutils.c:25:

../src/util/cutils.c: In function 'do_strtosz':
../src/util/cutils.c:245:61: warning: array subscript has type 'char' [-Wchar-subscripts]
245 | if (retval == 0 && *endptr == '.' && !isdigit(endptr[1])) {

isdigit() should not be used with plain "char" variables since these can be signed and isdigit() could be implemented as a macro that uses its parameter to index into an array. Use our wrapper qemu_isdigit() to fix this problem.

Quoted 4 lines
---
 util/cutils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|