Commit 0a599383 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

FlexeLint inspired polishing:

Better choice of data types.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2961 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 3276fcc0
...@@ -48,32 +48,33 @@ ...@@ -48,32 +48,33 @@
#include "libvarnish.h" #include "libvarnish.h"
static int static int
BackSlash(const char *s, int *res) BackSlash(const char *s, char *res)
{ {
int i, r; int r;
char c;
unsigned u; unsigned u;
assert(*s == '\\'); assert(*s == '\\');
r = i = 0; r = c = 0;
switch(s[1]) { switch(s[1]) {
case 'n': case 'n':
i = '\n'; c = '\n';
r = 2; r = 2;
break; break;
case 'r': case 'r':
i = '\r'; c = '\r';
r = 2; r = 2;
break; break;
case 't': case 't':
i = '\t'; c = '\t';
r = 2; r = 2;
break; break;
case '"': case '"':
i = '"'; c = '"';
r = 2; r = 2;
break; break;
case '\\': case '\\':
i = '\\'; c = '\\';
r = 2; r = 2;
break; break;
case '0': case '1': case '2': case '3': case '0': case '1': case '2': case '3':
...@@ -83,13 +84,14 @@ BackSlash(const char *s, int *res) ...@@ -83,13 +84,14 @@ BackSlash(const char *s, int *res)
break; break;
if (s[r] - '0' > 7) if (s[r] - '0' > 7)
break; break;
i <<= 3; c <<= 3; /*lint !e701 signed left shift */
i |= s[r] - '0'; c |= s[r] - '0';
} }
break; break;
case 'x': case 'x':
if (1 == sscanf(s + 1, "x%02x", &u)) { if (1 == sscanf(s + 1, "x%02x", &u)) {
i = u; assert(!(u & ~0xff));
c = u; /*lint !e734 loss of precision */
r = 4; r = 4;
} }
break; break;
...@@ -97,7 +99,7 @@ BackSlash(const char *s, int *res) ...@@ -97,7 +99,7 @@ BackSlash(const char *s, int *res)
break; break;
} }
if (res != NULL) if (res != NULL)
*res = i; *res = c;
return (r); return (r);
} }
...@@ -106,7 +108,7 @@ BackSlashDecode(const char *s, const char *e) ...@@ -106,7 +108,7 @@ BackSlashDecode(const char *s, const char *e)
{ {
const char *q; const char *q;
char *p, *r; char *p, *r;
int i, j; int i;
p = calloc((e - s) + 1, 1); p = calloc((e - s) + 1, 1);
if (p == NULL) if (p == NULL)
...@@ -116,9 +118,9 @@ BackSlashDecode(const char *s, const char *e) ...@@ -116,9 +118,9 @@ BackSlashDecode(const char *s, const char *e)
*r++ = *q++; *r++ = *q++;
continue; continue;
} }
i = BackSlash(q, &j); i = BackSlash(q, r);
q += i; q += i;
*r++ = j; r++;
} }
*r = '\0'; *r = '\0';
return (p); return (p);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment