Skip to contentSkip to conversation

strtosz() cleanup

PATCH In review [email protected] 3 participants 7 messages Jan 17, 2011

lore
Share & tools
lore
#0 lore raw

v2 cover strtosz() cleanup

From: Jes Sorensen <[email protected]>

Fix issue with signed char and isspace() as well as clean up switch statement using toupper().

V2 of the patch fixes some types in the commit messages and spells Eric correctly. My apologies for getting it wrong.

Jes Sorensen (2):
strtosz() use unsigned char as isspace() is not defined for signed
char
strtosz() use toupper() to simplify switch statement

 cutils.c |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)
Signature · 1 line
1.7.3.4
#1 lore raw

PATCH v2 1/2 strtosz() use unsigned char as isspace() is not defined for signed char

From: Jes Sorensen <[email protected]>

Bug pointed out by Eric Blake, thanks!

---
 cutils.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
cutils.c +2 -1
index 7984bc1..f97ef39 100644
@@ -294,7 +294,8 @@ int fcntl_setfl(int fd, int flag)
 ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
 {
     ssize_t retval = -1;
-    char *endptr, c, d;
+    char *endptr;
+    unsigned char c, d;
     int mul_required = 0;
     double val, mul, integral, fraction;
 
Signature · 1 line
1.7.3.4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] strtosz() use unsigned char as isspace() is not defined for signed char

Quoted 1 line · On Mon, Jan 17, 2011 at 3:14 PM, <[email protected]> wrote:

From: Jes Sorensen <[email protected]>

This is exactly why we have qemu_isspace().

#3 lore raw

PATCH v2 2/2 strtosz() use 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 f97ef39..f7aa90c 100644
@@ -323,16 +323,14 @@ ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
             d = c;
         }
     }
-    switch (d) {
+    switch (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 @@ ssize_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
#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] strtosz() use toupper() to simplify switch statement

Quoted 12 lines · On Mon, Jan 17, 2011 at 3:14 PM, <[email protected]> wrote:

From: Jes Sorensen <[email protected]>

---
 cutils.c |    7 +------

 1 files changed, 1 insertions(+), 6 deletions(-)
cutils.c +0 -0
index f97ef39..f7aa90c 100644

cutils.c ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) · line 326

Quoted 5 lines
cutils.c +1 -1
@@ -323,16 +323,14 @@ ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
             d = c;
         }
     }
-    switch (d) {
+    switch (toupper(d)) {

qemu_toupper()

#5 lore raw
In reply to [email protected]
Quoted 8 lines · On Mon, 2011-01-17 at 16:14 +0100, [email protected] wrote:

From: Jes Sorensen <[email protected]>

Fix issue with signed char and isspace() as well as clean up switch statement using toupper().

V2 of the patch fixes some types in the commit messages and spells Eric correctly. My apologies for getting it wrong.

Quoted 8 lines

Jes Sorensen (2):
strtosz() use unsigned char as isspace() is not defined for signed
char
strtosz() use toupper() to simplify switch statement

 cutils.c |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)

And the modf() usage? Or using STRTOSZ_DEFSUFFIX_* in the switch? Or avoiding the extra variable in 13/18? Thanks,

Alex

#6 lore raw
Quoted 14 lines · Alex Williamson
Quoted 13 lines · On Mon, 2011-01-17 at 16:14 +0100, [email protected] wrote:

From: Jes Sorensen <[email protected]>

Fix issue with signed char and isspace() as well as clean up switch statement using toupper().

V2 of the patch fixes some types in the commit messages and spells Eric correctly. My apologies for getting it wrong.

Jes Sorensen (2):
strtosz() use unsigned char as isspace() is not defined for signed
char
strtosz() use toupper() to simplify switch statement

Quoted 6 lines
Quoted 3 lines
 cutils.c |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)

And the modf() usage? Or using STRTOSZ_DEFSUFFIX_* in the switch? Or avoiding the extra variable in 13/18? Thanks,

Sorry, I'm crossing my mailing lists. These are a fine first step.