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
This commit is contained in:
Dimitry Andric 2011-12-17 15:33:26 +00:00
parent 17bbcc52d1
commit 7818f8df2e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=228636

View File

@ -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 @@ conv_c(PR *pr, u_char *p, size_t bufsize)
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;