From 20c70fcb90ac0586a1ab298f732f04b3d8d84dda Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 5 Oct 2011 09:41:54 +0000 Subject: Fix upper case hex and return -1 for invalid hex. svn path=/trunk/netsurf/; revision=12952 --- utils/nsurl.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'utils/nsurl.c') diff --git a/utils/nsurl.c b/utils/nsurl.c index e53c314d1..f21f02675 100644 --- a/utils/nsurl.c +++ b/utils/nsurl.c @@ -564,7 +564,7 @@ static size_t nsurl__get_longest_section(struct url_markers *m) * * \param c1 most significant hex digit * \param c2 least significant hex digit - * \return the total value of the two digit hex number + * \return the total value of the two digit hex number, or -ve if input not hex * * For unescaping url encoded characters. */ @@ -575,20 +575,24 @@ static inline int nsurl__get_ascii_offset(char c1, char c2) /* Use 1st char as most significant hex digit */ if (isdigit(c1)) offset = 16 * (c1 - '0'); - else if ((c1 >= 'a' && c1 <= 'f') || (c1 >= 'A' && c1 <= 'F')) + else if (c1 >= 'a' && c1 <= 'f') offset = 16 * (c1 - 'a' + 10); + else if (c1 >= 'A' && c1 <= 'F') + offset = 16 * (c1 - 'A' + 10); else - /* TODO: return something special to indicate error? */ - return 0; + /* Not valid hex */ + return -1; /* Use 2nd char as least significant hex digit and sum */ if (isdigit(c2)) offset += c2 - '0'; - else if ((c2 >= 'a' && c2 <= 'f') || (c2 >= 'A' && c2 <= 'F')) + else if (c2 >= 'a' && c2 <= 'f')) offset += c2 - 'a' + 10; + else if (c2 >= 'A' && c2 <= 'F')) + offset += c2 - 'A' + 10; else - /* TODO: return something special to indicate error? */ - return 0; + /* Not valid hex */ + return -1; return offset; } -- cgit v1.2.3