]> git.proxmox.com Git - mirror_qemu.git/commitdiff
Use qemu_tolower() and qemu_toupper(), not tolower() and toupper()
authorPeter Maydell <peter.maydell@linaro.org>
Thu, 20 Jul 2017 16:31:30 +0000 (17:31 +0100)
committerPeter Maydell <peter.maydell@linaro.org>
Fri, 21 Jul 2017 09:32:41 +0000 (10:32 +0100)
On NetBSD, where tolower() and toupper() are implemented using an
array lookup, the compiler warns if you pass a plain 'char'
to these functions:

gdbstub.c:914:13: warning: array subscript has type 'char'

This reflects the fact that toupper() and tolower() give
undefined behaviour if they are passed a value that isn't
a valid 'unsigned char' or EOF.

We have qemu_tolower() and qemu_toupper() to avoid this problem;
use them.

(The use in scsi-generic.c does not trigger the warning because
it passes a uint8_t; we switch it anyway, for consistency.)

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com> for the s390 part.
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Message-id: 1500568290-7966-1-git-send-email-peter.maydell@linaro.org

gdbstub.c
hw/s390x/s390-virtio-ccw.c
hw/scsi/scsi-generic.c
target/ppc/monitor.c

index f936ddd32dab77cafe2edb38ccfdfddbed14b490..2a94030d3b6e27d543213610b394e0241115f70c 100644 (file)
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -911,7 +911,7 @@ static int gdb_handle_vcont(GDBState *s, const char *p)
 
         cur_action = *p++;
         if (cur_action == 'C' || cur_action == 'S') {
-            cur_action = tolower(cur_action);
+            cur_action = qemu_tolower(cur_action);
             res = qemu_strtoul(p + 1, &p, 16, &tmp);
             if (res) {
                 goto out;
index ce3921e4dec0ece352485317292fa9140c0b1bea..1c7af39ce61361526bfc8e7555bc0253184f13a6 100644 (file)
@@ -318,7 +318,7 @@ static void machine_set_loadparm(Object *obj, const char *val, Error **errp)
     int i;
 
     for (i = 0; i < sizeof(ms->loadparm) && val[i]; i++) {
-        uint8_t c = toupper(val[i]); /* mimic HMC */
+        uint8_t c = qemu_toupper(val[i]); /* mimic HMC */
 
         if (('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || (c == '.') ||
             (c == ' ')) {
index a55ff87c228a9e3e518cc15f01183b0fe02f852f..7e1cbab77e8bbfac64ac1d5983ab8a4f7060b641 100644 (file)
@@ -406,7 +406,7 @@ static int read_naa_id(const uint8_t *p, uint64_t *p_wwn)
         }
         *p_wwn = 0;
         for (i = 8; i < 24; i++) {
-            char c = toupper(p[i]);
+            char c = qemu_toupper(p[i]);
             c -= (c >= '0' && c <= '9' ? '0' : 'A' - 10);
             *p_wwn = (*p_wwn << 4) | c;
         }
index b8f30e9eafd2bda6d131707cdbad81a557fab76e..14915119fc726dd190a1b1cc0e44812a51e6bd50 100644 (file)
@@ -115,14 +115,14 @@ int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval)
     CPUPPCState *env = &cpu->env;
 
     /* General purpose registers */
-    if ((tolower(name[0]) == 'r') &&
+    if ((qemu_tolower(name[0]) == 'r') &&
         ppc_cpu_get_reg_num(name + 1, ARRAY_SIZE(env->gpr), &regnum)) {
         *pval = env->gpr[regnum];
         return 0;
     }
 
     /* Floating point registers */
-    if ((tolower(name[0]) == 'f') &&
+    if ((qemu_tolower(name[0]) == 'f') &&
         ppc_cpu_get_reg_num(name + 1, ARRAY_SIZE(env->fpr), &regnum)) {
         *pval = env->fpr[regnum];
         return 0;