Better choice of data types.
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2961
d4fa192b-c00b-0410-8231-
f00ffab90ce4
#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':
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;
break;
}
if (res != NULL)
- *res = i;
+ *res = c;
return (r);
}
{
const char *q;
char *p, *r;
- int i, j;
+ int i;
p = calloc((e - s) + 1, 1);
if (p == NULL)
*r++ = *q++;
continue;
}
- i = BackSlash(q, &j);
+ i = BackSlash(q, r);
q += i;
- *r++ = j;
+ r++;
}
*r = '\0';
return (p);