Skip to content

Commit 25cfc1c

Browse files
committed
Refactor hex decode code.
1 parent 55cd6c6 commit 25cfc1c

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

‎cups/http-support.c‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,18 +1675,20 @@ http_copy_decode(char *dst, // O - Destination buffer
16751675
{
16761676
if (*src == '%' && decode)
16771677
{
1678-
if (_cups_isxdigit(src[1]) && _cups_isxdigit(src[2]))
1679-
{
1680-
// Grab a hex-encoded character...
1681-
*ptr++ = (char)((_cups_xdigit(src[1]) << 4) | _cups_xdigit(src[2]));
1682-
src += 2;
1683-
}
1684-
else
1678+
int x1, x2; // Hex digit values
1679+
1680+
if ((x1 = _cups_xdigit(src[1])) < 0 || (x2 = _cups_xdigit(src[2])) < 0)
16851681
{
16861682
// Bad hex-encoded character...
16871683
*ptr = '\0';
16881684
return (NULL);
16891685
}
1686+
else
1687+
{
1688+
// Grab a hex-encoded character...
1689+
*ptr++ = (char)((x1 << 4) | x2);
1690+
src += 2;
1691+
}
16901692
}
16911693
else if ((*src & 255) <= 0x20 || (*src & 255) >= 0x7f)
16921694
{

0 commit comments

Comments
 (0)