a9a8194dc4202814c36699790576ab7cc3a4535d galt Fri Feb 2 11:53:37 2018 -0800 Fixed bug in hex encoding for non-ascii high-bit characters. diff --git src/lib/htmshell.c src/lib/htmshell.c index 1475f6e..ad835ab 100644 --- src/lib/htmshell.c +++ src/lib/htmshell.c @@ -363,31 +363,32 @@ if (out) { if (outSize > 0 && (total+size+1) > outSize) // 1 for terminator { *out = 0; return -1; } if (size == 1) *out++ = c; else { char x; char *pf = prefix; while ((x = *pf++) != 0) *out++ = x; - char h1 = (c >> 4 ) + 0x30; if (h1 > 0x39) h1 += 7; + // use (unsigned char) to shift without sign-extension. We want zeros to be added on left side. + char h1 = ((unsigned char) c >> 4 ) + 0x30; if (h1 > 0x39) h1 += 7; *out++ = h1; char h2 = (c & 0xF) + 0x30; if (h2 > 0x39) h2 += 7; *out++ = h2; pf = postfix; while ((x = *pf++) != 0) *out++ = x; } } total += size; } while (c != 0); return total - 1; // do not count terminating 0 } static boolean decodeOneHexChar(char c, char *h) /* Return true if c is a hex char and decode it to h. */