diff options
author | dim <dim@FreeBSD.org> | 2011-12-17 15:33:26 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2011-12-17 15:33:26 +0000 |
commit | a382ad1946f3f24b9f25daa89b6e93725a3233ad (patch) | |
tree | d8ad7573aa3580990873b6751d202d6e44cfe2de /usr.bin/hexdump | |
parent | b4df21bd9deb47448179a13a58fbd43ad5ae75f4 (diff) | |
download | FreeBSD-src-a382ad1946f3f24b9f25daa89b6e93725a3233ad.zip FreeBSD-src-a382ad1946f3f24b9f25daa89b6e93725a3233ad.tar.gz |
Correct a logic error in usr.bin/hexdump/conv.c, found by clang.
Whenever the conv_c() function encounters an incomplete multibyte char,
it peeks ahead. It also sets p to peekbuf, to indicate it is still
processing the incomplete character.
However, on the next retry, it compares buf against peekbuf, which
always returns false, since both buf and peekbuf are local char arrays,
whose addresses are never the same.
Fix this by comparing against p instead, which was the intention. Also
turn peekbuf into an array of u_char, to prevent conversion warnings.
MFC after: 1 week
Diffstat (limited to 'usr.bin/hexdump')
-rw-r--r-- | usr.bin/hexdump/conv.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/usr.bin/hexdump/conv.c b/usr.bin/hexdump/conv.c index 7dd2c7f..2253dff 100644 --- a/usr.bin/hexdump/conv.c +++ b/usr.bin/hexdump/conv.c @@ -53,7 +53,7 @@ conv_c(PR *pr, u_char *p, size_t bufsize) wchar_t wc; size_t clen, oclen; int converr, pad, width; - char peekbuf[MB_LEN_MAX]; + u_char peekbuf[MB_LEN_MAX]; if (pr->mbleft > 0) { str = "**"; @@ -103,7 +103,7 @@ retry: if (clen == 0) clen = 1; else if (clen == (size_t)-1 || (clen == (size_t)-2 && - buf == peekbuf)) { + p == peekbuf)) { memset(&pr->mbstate, 0, sizeof(pr->mbstate)); wc = *p; clen = 1; |