]> err.no Git - varnish/commitdiff
FlexeLint inspired polishing:
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 19 Jul 2008 11:38:31 +0000 (11:38 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 19 Jul 2008 11:38:31 +0000 (11:38 +0000)
Better choice of data types.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2961 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/lib/libvarnish/argv.c

index c161cb9f91b137762c14b14b4720664d9cf2e48e..c95b65c7f6436adb440aa8e2b960a49a2a11863d 100644 (file)
 #include "libvarnish.h"
 
 static int
-BackSlash(const char *s, int *res)
+BackSlash(const char *s, char *res)
 {
-       int i, r;
+       int r;
+       char c;
        unsigned u;
 
        assert(*s == '\\');
-       r = i = 0;
+       r = c = 0;
        switch(s[1]) {
        case 'n':
-               i = '\n';
+               c = '\n';
                r = 2;
                break;
        case 'r':
-               i = '\r';
+               c = '\r';
                r = 2;
                break;
        case 't':
-               i = '\t';
+               c = '\t';
                r = 2;
                break;
        case '"':
-               i = '"';
+               c = '"';
                r = 2;
                break;
        case '\\':
-               i = '\\';
+               c = '\\';
                r = 2;
                break;
        case '0': case '1': case '2': case '3':
@@ -83,13 +84,14 @@ BackSlash(const char *s, int *res)
                                break;
                        if (s[r] - '0' > 7)
                                break;
-                       i <<= 3;
-                       i |= s[r] - '0';
+                       c <<= 3;        /*lint !e701 signed left shift */
+                       c |= s[r] - '0';
                }
                break;
        case 'x':
                if (1 == sscanf(s + 1, "x%02x", &u)) {
-                       i = u;
+                       assert(!(u & ~0xff));
+                       c = u;  /*lint !e734 loss of precision */
                        r = 4;
                }
                break;
@@ -97,7 +99,7 @@ BackSlash(const char *s, int *res)
                break;
        }
        if (res != NULL)
-               *res = i;
+               *res = c;
        return (r);
 }
 
@@ -106,7 +108,7 @@ BackSlashDecode(const char *s, const char *e)
 {
        const char *q;
        char *p, *r;
-       int i, j;
+       int i;
 
        p = calloc((e - s) + 1, 1);
        if (p == NULL)
@@ -116,9 +118,9 @@ BackSlashDecode(const char *s, const char *e)
                        *r++ = *q++;
                        continue;
                }
-               i = BackSlash(q, &j);
+               i = BackSlash(q, r);
                q += i;
-               *r++ = j;
+               r++;
        }
        *r = '\0';
        return (p);