Skip to contentSkip to conversation

strtosz() cleanups

PATCH Applied [email protected] 4 participants 22 messages Jan 24, 2011 – Jan 25, 2011

lore
Share & tools
lore
#0 lore raw

v4 cover strtosz() cleanups

From: Jes Sorensen <[email protected]>

Hi,

Here is an updated version of the strtosz() fixes that were discussed earlier. Per discussing with Anthony on irc, he is ok with them going in like this.

This is a respin to fix a patch conflict in the block tree, and it pulls the two patch sets into one set of four patches instead. No functional change.

Cheers,
Jes

Jes Sorensen (4):
strtosz(): use unsigned char and switch to qemu_isspace() strtosz() use qemu_toupper() to simplify switch statement strtosz(): Fix name confusion in use of modf() strtosz(): Use suffix macros in switch() statement

 cutils.c |   28 ++++++++++++----------------
 1 files changed, 12 insertions(+), 16 deletions(-)
Signature · 1 line
1.7.3.4
#1 lore raw

PATCH v4 1/4 strtosz(): use unsigned char and switch to qemu_isspace()

From: Jes Sorensen <[email protected]>

isspace() behavior is undefined for signed char.

Bug pointed out by Eric Blake, thanks!

---
 cutils.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
cutils.c +4 -3
index 4d2e27c..a067cf4 100644
@@ -294,7 +294,8 @@ int fcntl_setfl(int fd, int flag)
 int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
 {
     int64_t retval = -1;
-    char *endptr, c, d;
+    char *endptr;
+    unsigned char c, d;
     int mul_required = 0;
     double val, mul, integral, fraction;
 
@@ -314,7 +315,7 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
      */
     c = *endptr;
     d = c;
-    if (isspace(c) || c == '\0' || c == ',') {
+    if (qemu_isspace(c) || c == '\0' || c == ',') {
         c = 0;
         if (default_suffix) {
             d = default_suffix;
@@ -361,7 +362,7 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
      */
     if (c != 0) {
         endptr++;
-        if (!isspace(*endptr) && *endptr != ',' && *endptr != 0) {
+        if (!qemu_isspace(*endptr) && *endptr != ',' && *endptr != 0) {
             goto fail;
         }
     }
Signature · 1 line
1.7.3.4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/4] strtosz(): use unsigned char and switch to qemu_isspace()

Quoted 16 lines · [email protected] writes:

From: Jes Sorensen <[email protected]>

isspace() behavior is undefined for signed char.

Bug pointed out by Eric Blake, thanks!

---
 cutils.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
cutils.c +0 -0
index 4d2e27c..a067cf4 100644

cutils.c int fcntl_setfl(int fd, int flag) · line 301

Quoted 9 lines
cutils.c +2 -1
@@ -294,7 +294,8 @@ int fcntl_setfl(int fd, int flag)
 int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
 {
     int64_t retval = -1;
-    char *endptr, c, d;
+    char *endptr;
+    unsigned char c, d;
     int mul_required = 0;
     double val, mul, integral, fraction;
 

I doubt this hunk is still needed.

Quoted 18 lines
cutils.c +2 -2
@@ -314,7 +315,7 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
      */
     c = *endptr;
     d = c;
-    if (isspace(c) || c == '\0' || c == ',') {
+    if (qemu_isspace(c) || c == '\0' || c == ',') {
         c = 0;
         if (default_suffix) {
             d = default_suffix;
@@ -361,7 +362,7 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
      */
     if (c != 0) {
         endptr++;
-        if (!isspace(*endptr) && *endptr != ',' && *endptr != 0) {
+        if (!qemu_isspace(*endptr) && *endptr != ',' && *endptr != 0) {
             goto fail;
         }
     }
#3 lore raw

Re: [Qemu-devel] [PATCH 1/4] strtosz(): use unsigned char and switch to qemu_isspace()

Quoted 13 lines · Markus Armbruster
Quoted 11 lines · [email protected] writes:

From: Jes Sorensen <[email protected]>

isspace() behavior is undefined for signed char.

Bug pointed out by Eric Blake, thanks!

---
 cutils.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
Quoted 16 lines
Quoted 5 lines
cutils.c +0 -0
index 4d2e27c..a067cf4 100644

cutils.c int fcntl_setfl(int fd, int flag) · line 301

Quoted 9 lines
cutils.c +2 -1
@@ -294,7 +294,8 @@ int fcntl_setfl(int fd, int flag)
 int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
 {
     int64_t retval = -1;
-    char *endptr, c, d;
+    char *endptr;
+    unsigned char c, d;
     int mul_required = 0;
     double val, mul, integral, fraction;
 

I doubt this hunk is still needed.

It isn't strictly due to qemu_toupper() but it is prettier to match the real behavior of pure toupper() anyway.

Jes

#4 lore raw

Re: [Qemu-devel] [PATCH 1/4] strtosz(): use unsigned char and switch to qemu_isspace()

Quoted 31 lines · Jes Sorensen
Quoted 13 lines · Markus Armbruster
Quoted 11 lines · [email protected] writes:

From: Jes Sorensen <[email protected]>

isspace() behavior is undefined for signed char.

Bug pointed out by Eric Blake, thanks!

---
 cutils.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
Quoted 16 lines
Quoted 5 lines
cutils.c +0 -0
index 4d2e27c..a067cf4 100644

cutils.c int fcntl_setfl(int fd, int flag) · line 301

Quoted 9 lines
cutils.c +2 -1
@@ -294,7 +294,8 @@ int fcntl_setfl(int fd, int flag)
 int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
 {
     int64_t retval = -1;
-    char *endptr, c, d;
+    char *endptr;
+    unsigned char c, d;
     int mul_required = 0;
     double val, mul, integral, fraction;
 

I doubt this hunk is still needed.

Quoted 2 lines

It isn't strictly due to qemu_toupper() but it is prettier to match the real behavior of pure toupper() anyway.

Frequent casting between signed and unsigned has been shown to cause headaches in laboratory rats.

#5 lore raw

PATCH v4 2/4 strtosz() use qemu_toupper() to simplify switch statement

In reply to [email protected]

From: Jes Sorensen <[email protected]>

---
 cutils.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)
cutils.c +1 -6
index a067cf4..78d35e2 100644
@@ -323,16 +323,14 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
             d = c;
         }
     }
-    switch (d) {
+    switch (qemu_toupper(d)) {
     case 'B':
-    case 'b':
         mul = 1;
         if (mul_required) {
             goto fail;
         }
         break;
     case 'K':
-    case 'k':
         mul = 1 << 10;
         break;
     case 0:
@@ -340,15 +338,12 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
             goto fail;
         }
     case 'M':
-    case 'm':
         mul = 1ULL << 20;
         break;
     case 'G':
-    case 'g':
         mul = 1ULL << 30;
         break;
     case 'T':
-    case 't':
         mul = 1ULL << 40;
         break;
     default:
Signature · 1 line
1.7.3.4
#6 lore raw

PATCH v4 3/4 strtosz(): Fix name confusion in use of modf()

In reply to [email protected]

From: Jes Sorensen <[email protected]>

---
 cutils.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
cutils.c +2 -2
index 78d35e2..369a016 100644
@@ -304,8 +304,8 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
     if (isnan(val) || endptr == nptr || errno != 0) {
         goto fail;
     }
-    integral = modf(val, &fraction);
-    if (integral != 0) {
+    fraction = modf(val, &integral);
+    if (fraction != 0) {
         mul_required = 1;
     }
     /*
Signature · 1 line
1.7.3.4
#7 lore raw

PATCH v4 4/4 strtosz(): Use suffix macros in switch() statement

In reply to [email protected]

From: Jes Sorensen <[email protected]>

---
 cutils.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
cutils.c +5 -5
index 369a016..8d562b2 100644
@@ -324,26 +324,26 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
         }
     }
     switch (qemu_toupper(d)) {
-    case 'B':
+    case STRTOSZ_DEFSUFFIX_B:
         mul = 1;
         if (mul_required) {
             goto fail;
         }
         break;
-    case 'K':
+    case STRTOSZ_DEFSUFFIX_KB:
         mul = 1 << 10;
         break;
     case 0:
         if (mul_required) {
             goto fail;
         }
-    case 'M':
+    case STRTOSZ_DEFSUFFIX_MB:
         mul = 1ULL << 20;
         break;
-    case 'G':
+    case STRTOSZ_DEFSUFFIX_GB:
         mul = 1ULL << 30;
         break;
-    case 'T':
+    case STRTOSZ_DEFSUFFIX_TB:
         mul = 1ULL << 40;
         break;
     default:
Signature · 1 line
1.7.3.4
#8 lore raw

Re: [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement

Quoted 33 lines · [email protected] writes:

From: Jes Sorensen <[email protected]>

---
 cutils.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
cutils.c +3 -3
index 369a016..8d562b2 100644
@@ -324,26 +324,26 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
         }
     }
     switch (qemu_toupper(d)) {
-    case 'B':
+    case STRTOSZ_DEFSUFFIX_B:
         mul = 1;
         if (mul_required) {
             goto fail;
         }
         break;
-    case 'K':
+    case STRTOSZ_DEFSUFFIX_KB:
         mul = 1 << 10;
         break;
     case 0:
         if (mul_required) {
             goto fail;
         }
-    case 'M':
+    case STRTOSZ_DEFSUFFIX_MB:
         mul = 1ULL << 20;

cutils.c int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) · line 349

Quoted 10 lines
cutils.c +2 -2
         break;
-    case 'G':
+    case STRTOSZ_DEFSUFFIX_GB:
         mul = 1ULL << 30;
         break;
-    case 'T':
+    case STRTOSZ_DEFSUFFIX_TB:
         mul = 1ULL << 40;
         break;
     default:

Phony abstraction. And it leaks: code here assumes the STRTOSZ_DEFSUFFIX_T* are all upper case.

#9 lore raw

Re: [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement

Quoted 40 lines · Markus Armbruster
Quoted 38 lines · [email protected] writes:

From: Jes Sorensen <[email protected]>

---
 cutils.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
cutils.c +4 -4
index 369a016..8d562b2 100644
@@ -324,26 +324,26 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
         }
     }
     switch (qemu_toupper(d)) {
-    case 'B':
+    case STRTOSZ_DEFSUFFIX_B:
         mul = 1;
         if (mul_required) {
             goto fail;
         }
         break;
-    case 'K':
+    case STRTOSZ_DEFSUFFIX_KB:
         mul = 1 << 10;
         break;
     case 0:
         if (mul_required) {
             goto fail;
         }
-    case 'M':
+    case STRTOSZ_DEFSUFFIX_MB:
         mul = 1ULL << 20;
         break;
-    case 'G':
+    case STRTOSZ_DEFSUFFIX_GB:
         mul = 1ULL << 30;
         break;
Quoted 8 lines

cutils.c int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) · line 349

Quoted 5 lines
cutils.c +1 -1
-    case 'T':
+    case STRTOSZ_DEFSUFFIX_TB:
         mul = 1ULL << 40;
         break;
     default:

Phony abstraction. And it leaks: code here assumes the STRTOSZ_DEFSUFFIX_T* are all upper case.

qemu_toupper() - whats the problem?

Jes

#10 lore raw

Re: [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement

Quoted 50 lines · Jes Sorensen
Quoted 40 lines · Markus Armbruster
Quoted 38 lines · [email protected] writes:

From: Jes Sorensen <[email protected]>

---
 cutils.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
cutils.c +4 -4
index 369a016..8d562b2 100644
@@ -324,26 +324,26 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
         }
     }
     switch (qemu_toupper(d)) {
-    case 'B':
+    case STRTOSZ_DEFSUFFIX_B:
         mul = 1;
         if (mul_required) {
             goto fail;
         }
         break;
-    case 'K':
+    case STRTOSZ_DEFSUFFIX_KB:
         mul = 1 << 10;
         break;
     case 0:
         if (mul_required) {
             goto fail;
         }
-    case 'M':
+    case STRTOSZ_DEFSUFFIX_MB:
         mul = 1ULL << 20;
         break;
-    case 'G':
+    case STRTOSZ_DEFSUFFIX_GB:
         mul = 1ULL << 30;
         break;
Quoted 8 lines

cutils.c int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) · line 349

Quoted 5 lines
cutils.c +1 -1
-    case 'T':
+    case STRTOSZ_DEFSUFFIX_TB:
         mul = 1ULL << 40;
         break;
     default:

Phony abstraction. And it leaks: code here assumes the STRTOSZ_DEFSUFFIX_T* are all upper case.

Quoted 1 line

qemu_toupper() - whats the problem?

If a STRTOSZ_DEFSUFFIX_T? expands to a lower case character, its case will not match any input.

#11 lore raw

Re: [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement

Quoted 11 lines · Markus Armbruster
Quoted 9 lines
Quoted 9 lines
Quoted 7 lines

+ case STRTOSZ_DEFSUFFIX_TB:

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
         mul = 1ULL << 40;
         break;
     default:

Phony abstraction. And it leaks: code here assumes the STRTOSZ_DEFSUFFIX_T* are all upper case.

qemu_toupper() - whats the problem?

If a STRTOSZ_DEFSUFFIX_T? expands to a lower case character, its case will not match any input.

Right, so one has to be careful when adding new suffix constants. However given that we already have all the likely to be used ones for the near future, that isn't exactly a big issue.

On the other hand forcing the use of the macros makes it less likely that someone specifies an unsupported constant by hitting 'y' instead of 't' or similar.

Jes

#12 lore raw

Re: [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement

Quoted 6 lines · Jes Sorensen
Quoted 5 lines · Markus Armbruster
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

+ case STRTOSZ_DEFSUFFIX_TB:

Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
         mul = 1ULL << 40;
         break;
     default:
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

Phony abstraction. And it leaks: code here assumes the STRTOSZ_DEFSUFFIX_T* are all upper case.

qemu_toupper() - whats the problem?

If a STRTOSZ_DEFSUFFIX_T? expands to a lower case character, its case will not match any input.

Right, so one has to be careful when adding new suffix constants.

Calls for a comment right next to the definition of the STRTOSZ_DEFSUFFIX_T*.

I hate unstated restrictions that are hidden far away from the place where you can break them.

Quoted 6 lines

However given that we already have all the likely to be used ones for the near future, that isn't exactly a big issue.

On the other hand forcing the use of the macros makes it less likely that someone specifies an unsupported constant by hitting 'y' instead of 't' or similar.

Takes a combination of butterfingers, cross-eyedness, and near-total incompetence at basic smoke-testing.

#13 lore raw

Re: [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement

Quoted 5 lines · Markus Armbruster
Quoted 4 lines · Jes Sorensen
Quoted 3 lines
Quoted 1 line
Quoted 1 line

qemu_toupper() - whats the problem?

If a STRTOSZ_DEFSUFFIX_T? expands to a lower case character, its case will not match any input.

Quoted 7 lines
Quoted 1 line

Right, so one has to be careful when adding new suffix constants.

Calls for a comment right next to the definition of the STRTOSZ_DEFSUFFIX_T*.

I hate unstated restrictions that are hidden far away from the place where you can break them.

Well I am fine with a comment in the code.

Quoted 9 lines
Quoted 6 lines

However given that we already have all the likely to be used ones for the near future, that isn't exactly a big issue.

On the other hand forcing the use of the macros makes it less likely that someone specifies an unsupported constant by hitting 'y' instead of 't' or similar.

Takes a combination of butterfingers, cross-eyedness, and near-total incompetence at basic smoke-testing.

Not really, all it takes is someone writing a piece of code, not thinking about it, therefore only testing things where a suffix is specified as an argument and it gets missed.

Jes

#14 lore raw

Re: [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement

Quoted 8 lines · Jes Sorensen
Quoted 7 lines · Markus Armbruster
Quoted 5 lines · Jes Sorensen
Quoted 3 lines
Quoted 1 line
Quoted 1 line

qemu_toupper() - whats the problem?

If a STRTOSZ_DEFSUFFIX_T? expands to a lower case character, its case will not match any input.

Right, so one has to be careful when adding new suffix constants.

Quoted 7 lines
Quoted 5 lines

Calls for a comment right next to the definition of the STRTOSZ_DEFSUFFIX_T*.

I hate unstated restrictions that are hidden far away from the place where you can break them.

Well I am fine with a comment in the code.

Such a comment improves it from "wrong" to merely "ugly". I can live with that.

Thanks.

[...]

#15 lore raw

Re: [Qemu-devel] [PATCH 4/4] strtosz(): Use suffix macros in switch() statement

Quoted 13 lines · Markus Armbruster
Quoted 11 lines · Jes Sorensen
Quoted 10 lines · Markus Armbruster
Quoted 5 lines · Jes Sorensen
Quoted 3 lines
Quoted 1 line
Quoted 1 line

qemu_toupper() - whats the problem?

If a STRTOSZ_DEFSUFFIX_T? expands to a lower case character, its case will not match any input.

Right, so one has to be careful when adding new suffix constants.

Calls for a comment right next to the definition of the STRTOSZ_DEFSUFFIX_T*.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

I hate unstated restrictions that are hidden far away from the place where you can break them.

Well I am fine with a comment in the code.

Such a comment improves it from "wrong" to merely "ugly". I can live with that.

I realize that you view it as such, in other eyes it goes from hackish to correct ... there is zero point in arguing over this, we can just agree to disagree.

Jes

Applied
#16 lore raw
In reply to [email protected]

Am 24.01.2011 16:33, schrieb [email protected]:

Quoted 16 lines

From: Jes Sorensen <[email protected]>

Hi,

Here is an updated version of the strtosz() fixes that were discussed earlier. Per discussing with Anthony on irc, he is ok with them going in like this.

This is a respin to fix a patch conflict in the block tree, and it pulls the two patch sets into one set of four patches instead. No functional change.

Cheers,
Jes

Quoted 9 lines

Jes Sorensen (4):
strtosz(): use unsigned char and switch to qemu_isspace() strtosz() use qemu_toupper() to simplify switch statement strtosz(): Fix name confusion in use of modf() strtosz(): Use suffix macros in switch() statement

 cutils.c |   28 ++++++++++++----------------
 1 files changed, 12 insertions(+), 16 deletions(-)

Thanks, applied all to the block branch.

Kevin

#17 lore raw

Am 24.01.2011 16:45, schrieb Kevin Wolf:

Quoted 23 lines

Am 24.01.2011 16:33, schrieb [email protected]:

Quoted 22 lines

From: Jes Sorensen <[email protected]>

Hi,

Here is an updated version of the strtosz() fixes that were discussed earlier. Per discussing with Anthony on irc, he is ok with them going in like this.

This is a respin to fix a patch conflict in the block tree, and it pulls the two patch sets into one set of four patches instead. No functional change.

Cheers,
Jes

Jes Sorensen (4):
strtosz(): use unsigned char and switch to qemu_isspace() strtosz() use qemu_toupper() to simplify switch statement strtosz(): Fix name confusion in use of modf() strtosz(): Use suffix macros in switch() statement

Quoted 7 lines
Quoted 3 lines

cutils.c | 28 ++++++++++++----------------

1 files changed, 12 insertions(+), 16 deletions(-)

Thanks, applied all to the block branch.

Kevin

There was some discussion regarding this patch set. I agree with Markus that part of the first patch should be removed: don't change char to unsigned char.

It's not necessary, and the result is, that now unsigned chars are assigned to chars which might raise future compiler warnings.

Stefan

#18 lore raw
Quoted 3 lines · Stefan Weil

There was some discussion regarding this patch set. I agree with Markus that part of the first patch should be removed: don't change char to unsigned char.

The unsigned char should definitely go in, leaving it as a signed char doesn't serve any purpose.

Quoted 3 lines

It's not necessary, and the result is, that now unsigned chars are assigned to chars which might raise future compiler warnings.

We already do that cast by calling qemu_toupper() and qemu_isspace() so that argument is void.

Jes

#19 lore raw
Quoted 7 lines · Jes Sorensen
Quoted 3 lines · Stefan Weil

There was some discussion regarding this patch set. I agree with Markus that part of the first patch should be removed: don't change char to unsigned char.

The unsigned char should definitely go in, leaving it as a signed char doesn't serve any purpose.

Leaving something as is doesn't need justification. Changing it does. The justification presented so far was "it is prettier to match the real behavior of pure toupper()". Which I don't buy. But without commit access, I'm not a buyer.

[...]

#20 lore raw
Quoted 7 lines · Markus Armbruster
Quoted 5 lines · Jes Sorensen
Quoted 3 lines · Stefan Weil

There was some discussion regarding this patch set. I agree with Markus that part of the first patch should be removed: don't change char to unsigned char.

Quoted 7 lines
Quoted 2 lines

The unsigned char should definitely go in, leaving it as a signed char doesn't serve any purpose.

Leaving something as is doesn't need justification. Changing it does. The justification presented so far was "it is prettier to match the real behavior of pure toupper()". Which I don't buy. But without commit access, I'm not a buyer.

Well that is just too bad. qemu_toupper() is a hack around the fact that people often forget to use the right type, it is not an excuse for using the wrong type in the code.

Jes

#21 lore raw
Quoted 11 lines · Jes Sorensen
Quoted 10 lines · Markus Armbruster
Quoted 7 lines · Jes Sorensen
Quoted 3 lines · Stefan Weil

There was some discussion regarding this patch set. I agree with Markus that part of the first patch should be removed: don't change char to unsigned char.

The unsigned char should definitely go in, leaving it as a signed char doesn't serve any purpose.

Quoted 8 lines
Quoted 4 lines

Leaving something as is doesn't need justification. Changing it does. The justification presented so far was "it is prettier to match the real behavior of pure toupper()". Which I don't buy. But without commit access, I'm not a buyer.

Well that is just too bad. qemu_toupper() is a hack around the fact that people often forget to use the right type, it is not an excuse for using the wrong type in the code.

qemu_toupper() is designed to work correctly for any character argument, be it signed or unsigned.

The fact that toupper() works only for unsigned character values is irrelevant for qemu_toupper().

The fact that qemu_toupper()'s implementation uses toupper() is an implementation detail.