* - "0xnn" or "0Xnn" is specially catered for.
* - The first non-hex-digit character (apart from possibly leading "0x"
* finishes the conversion and skips the rest of the input.
+ * - A single hex-digit character at the end of the string is skipped.
*
* valid examples: "0A5D15"; "0x123456"
*/
i += 2; /* skip two chars */
}
- for (; i < strhex_len && strhex[i] != 0; i++) {
+ for (; i+1 < strhex_len && strhex[i] != 0 && strhex[i+1] != 0; i++) {
p1 = strchr(hexchars, toupper((unsigned char)strhex[i]));
if (p1 == NULL) {
break;