Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Dec 2011 15:33:26 +0000 (UTC)
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r228636 - head/usr.bin/hexdump
Message-ID:  <201112171533.pBHFXQis065209@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dim
Date: Sat Dec 17 15:33:26 2011
New Revision: 228636
URL: http://svn.freebsd.org/changeset/base/228636

Log:
  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

Modified:
  head/usr.bin/hexdump/conv.c

Modified: head/usr.bin/hexdump/conv.c
==============================================================================
--- head/usr.bin/hexdump/conv.c	Sat Dec 17 15:31:00 2011	(r228635)
+++ head/usr.bin/hexdump/conv.c	Sat Dec 17 15:33:26 2011	(r228636)
@@ -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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201112171533.pBHFXQis065209>