Skip to contentSkip to conversation

qapi: fix input visitor bugs

PATCH In review Michael S. Tsirkin 2 participants 3 messages Jun 18, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qapi: fix input visitor bugs

Remove dead code. Reset errno to 0 before each strtoull call, as the man page requires.

---
 qapi/string-input-visitor.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
qapi/string-input-visitor.c +4 -5
index 72722e6..d8a8db0 100644
@@ -48,11 +48,10 @@ static void parse_str(StringInputVisitor *siv, Error **errp)
         return;
     }
 
-    errno = 0;
     do {
+        errno = 0;
         start = strtoll(str, &endptr, 0);
-        if (errno == 0 && endptr > str && INT64_MIN <= start &&
-            start <= INT64_MAX) {
+        if (errno == 0 && endptr > str) {
             if (*endptr == '\0') {
                 cur = g_malloc0(sizeof(*cur));
                 cur->begin = start;
@@ -63,9 +62,9 @@ static void parse_str(StringInputVisitor *siv, Error **errp)
                 str = NULL;
             } else if (*endptr == '-') {
                 str = endptr + 1;
+                errno = 0;
                 end = strtoll(str, &endptr, 0);
-                if (errno == 0 && endptr > str &&
-                    INT64_MIN <= end && end <= INT64_MAX && start <= end &&
+                if (errno == 0 && endptr > str && start <= end &&
                     (start > INT64_MAX - 65536 ||
                      end < start + 65536)) {
                     if (*endptr == '\0') {
Signature · 1 line
MST
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Michael S. Tsirkin

Remove dead code. Reset errno to 0 before each strtoull call, as the man page requires.

---
 qapi/string-input-visitor.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
qapi/string-input-visitor.c +0 -0
index 72722e6..d8a8db0 100644

qapi/string-input-visitor.c static void parse_str(StringInputVisitor *siv, Error **errp) · line 54

Quoted 10 lines
qapi/string-input-visitor.c +2 -3
@@ -48,11 +48,10 @@ static void parse_str(StringInputVisitor *siv, Error **errp)
         return;
     }
 
-    errno = 0;
     do {
+        errno = 0;
         start = strtoll(str, &endptr, 0);
-        if (errno == 0 && endptr > str && INT64_MIN <= start &&
-            start <= INT64_MAX) {
+        if (errno == 0 && endptr > str) {

Based on this conditional...

qapi/string-input-visitor.c static void parse_str(StringInputVisitor *siv, Error **errp) · line 65

Quoted 8 lines
qapi/string-input-visitor.c +1 -0
             if (*endptr == '\0') {
                 cur = g_malloc0(sizeof(*cur));
                 cur->begin = start;
@@ -63,9 +62,9 @@ static void parse_str(StringInputVisitor *siv, Error **errp)
                 str = NULL;
             } else if (*endptr == '-') {
                 str = endptr + 1;
+                errno = 0;

...this assignment to errno is dead code (we already know it is 0). But I'd rather leave it in for robustness sake (any change to intermediate code may change the situation where we are no longer assured of the current value of errno at this point).

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
Quoted 28 lines · Eric Blake
Quoted 14 lines · Michael S. Tsirkin

Remove dead code. Reset errno to 0 before each strtoull call, as the man page requires.

---
 qapi/string-input-visitor.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
qapi/string-input-visitor.c +0 -0
index 72722e6..d8a8db0 100644

qapi/string-input-visitor.c static void parse_str(StringInputVisitor *siv, Error **errp) · line 54

Quoted 10 lines
qapi/string-input-visitor.c +2 -3
@@ -48,11 +48,10 @@ static void parse_str(StringInputVisitor *siv, Error **errp)
         return;
     }
 
-    errno = 0;
     do {
+        errno = 0;
         start = strtoll(str, &endptr, 0);
-        if (errno == 0 && endptr > str && INT64_MIN <= start &&
-            start <= INT64_MAX) {
+        if (errno == 0 && endptr > str) {

Based on this conditional...

Quoted 13 lines

qapi/string-input-visitor.c static void parse_str(StringInputVisitor *siv, Error **errp) · line 65

Quoted 8 lines
qapi/string-input-visitor.c +1 -0
             if (*endptr == '\0') {
                 cur = g_malloc0(sizeof(*cur));
                 cur->begin = start;
@@ -63,9 +62,9 @@ static void parse_str(StringInputVisitor *siv, Error **errp)
                 str = NULL;
             } else if (*endptr == '-') {
                 str = endptr + 1;
+                errno = 0;

...this assignment to errno is dead code (we already know it is 0). But I'd rather leave it in for robustness sake (any change to intermediate code may change the situation where we are no longer assured of the current value of errno at this point).

Exactly, that's why I put it here.

Quoted 1 line

Thanks!

Quoted 4 lines
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org