From: phk Date: Sat, 19 Jul 2008 11:38:31 +0000 (+0000) Subject: FlexeLint inspired polishing: X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84fedb61c801905fcac762d647cea15852f5a8ef;p=varnish FlexeLint inspired polishing: Better choice of data types. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2961 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/lib/libvarnish/argv.c b/varnish-cache/lib/libvarnish/argv.c index c161cb9f..c95b65c7 100644 --- a/varnish-cache/lib/libvarnish/argv.c +++ b/varnish-cache/lib/libvarnish/argv.c @@ -48,32 +48,33 @@ #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);