alternative decodeString() for httpd.c
Robert P. J. Day
rpjday at mindspring.com
Sat Apr 15 23:00:20 UTC 2006
given that the current implementation of decodeString() in httpd.c
seems to have an error, here's an alternative that appears to do the
right thing and also turns out to be 60 bytes smaller after
compilation and stripping. thoughts?
static char *decodeString(char *orig, int flag_plus_to_space)
{
char *string = orig;
char *ptr = string;
unsigned int value1, value2 ;
while (*ptr) {
if (*ptr == '+' && flag_plus_to_space) {
*string++ = ' '; ptr++;
continue ;
}
if (*ptr != '%') {
*string++ = *ptr++;
continue ;
}
if(sscanf(ptr+1, "%1X%1X", &value1, &value2) != 2) {
*string++ = *ptr++ ;
continue ;
}
value1 = value1 * 16 + value2 ;
*string++ = value1 ;
ptr += 3 ;
}
*string = '\0';
return orig;
}
rday
More information about the busybox
mailing list