summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2011-10-05 09:41:54 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2011-10-05 09:41:54 +0000
commit20c70fcb90ac0586a1ab298f732f04b3d8d84dda (patch)
tree063d86c226c0046196a30fa381daf97468ac6ff6 /utils
parentc18c9b55112cdd1daea7d93f674057a73eb414a6 (diff)
downloadnetsurf-20c70fcb90ac0586a1ab298f732f04b3d8d84dda.tar.gz
netsurf-20c70fcb90ac0586a1ab298f732f04b3d8d84dda.tar.bz2
Fix upper case hex and return -1 for invalid hex.
svn path=/trunk/netsurf/; revision=12952
Diffstat (limited to 'utils')
-rw-r--r--utils/nsurl.c18
1 files changed, 11 insertions, 7 deletions
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;
}