]> git.kaiwu.me - haproxy.git/commitdiff
[BUG] fix error checking in strl2ic/strl2uic()
authorWilly Tarreau <w@1wt.eu>
Thu, 25 Oct 2007 07:42:24 +0000 (09:42 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 1 Nov 2007 22:13:27 +0000 (23:13 +0100)
The strl2ic() and strl2uic() primitives used to convert string to
integers could return 10 times the value read if they stopped on
non-digit because of a mis-placed loop exit.
(cherry picked from commit 3f0c9761352efc06b498ad43f314b136d92cf05d)

include/common/standard.h
src/standard.c

index 34d6b4949190a584434457cb7d755e0323cbbec2..d8b56b68da73cf459d43f5852fca37adedaec965 100644 (file)
@@ -153,14 +153,14 @@ static inline unsigned int __strl2ui(const char *s, int len)
 static inline unsigned int __strl2uic(const char *s, int len)
 {
        unsigned int i = 0;
-       unsigned int j;
+       unsigned int j, k;
 
        while (len-- > 0) {
                j = (*s++) - '0';
-               i = i * 10;
+               k = i * 10;
                if (j > 9)
                        break;
-               i += j;
+               i = k + j;
        }
        return i;
 }
index 69c8f4f5dc10a557cc8090964be0b7a7579bca33..80e0d1b4a384f3d27b40ea329259c129b4bf2348 100644 (file)
@@ -248,27 +248,27 @@ unsigned int strl2uic(const char *s, int len)
 int strl2ic(const char *s, int len)
 {
        int i = 0;
-       int j;
+       int j, k;
 
        if (len > 0) {
                if (*s != '-') {
                        /* positive number */
                        while (len-- > 0) {
                                j = (*s++) - '0';
-                               i = i * 10;
+                               k = i * 10;
                                if (j > 9)
                                        break;
-                               i += j;
+                               i = k + j;
                        }
                } else {
                        /* negative number */
                        s++;
                        while (--len > 0) {
                                j = (*s++) - '0';
-                               i = i * 10;
+                               k = i * 10;
                                if (j > 9)
                                        break;
-                               i -= j;
+                               i = k - j;
                        }
                }
        }