Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LBoaT-0003PD-FM for qemu-devel@nongnu.org; Sun, 14 Dec 2008 05:52:37 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LBoaS-0003OR-OS for qemu-devel@nongnu.org; Sun, 14 Dec 2008 05:52:36 -0500 Received: from [199.232.76.173] (port=43593 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LBoaS-0003OH-9T for qemu-devel@nongnu.org; Sun, 14 Dec 2008 05:52:36 -0500 Received: from mail.gmx.net ([213.165.64.20]:50419) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1LBoaR-0001hu-N6 for qemu-devel@nongnu.org; Sun, 14 Dec 2008 05:52:36 -0500 Date: Sun, 14 Dec 2008 11:54:02 +0100 (CET) From: Johannes Schindelin Subject: Re: [Qemu-devel] [6023] Use a hex value instead of possibly ambiguous 8 bit character In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: qemu-devel@nongnu.org Hi, On Sun, 14 Dec 2008, Blue Swirl wrote: > On 12/14/08, Johannes Schindelin wrote: > > > On Sun, 14 Dec 2008, Blue Swirl wrote: > > > > > Revision: 6023 > > > http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6023 > > > Author: blueswir1 > > > Date: 2008-12-14 09:30:41 +0000 (Sun, 14 Dec 2008) > > > > > > Log Message: > > > ----------- > > > Use a hex value instead of possibly ambiguous 8 bit character > > > > > > /me is curious: how could buffer[j] = '\xb0' be ambiguous when buffer is > > of type char *? It's not as if C did UTF-8 conversion with chars. > > The diff does not show it properly, there was a 8 bit character between > the apostrophes, not \xb0. Right. > One day some compiler might want to parse the source text as UTF-8, then > byte B0 and apostrophe after it could decode to something different with > mysterious side effects. This will not be the case unless sizeof(char) will be anything else than 1. Which will be, uhm, never. > Patches welcome :) [PATCH] block-vvfat: fix warnings and simplify ADD_CHAR when compiling with DEBUG ADD_CHAR() now substitutes non-ASCII characters with '.' to avoid the assumption that the terminal is ISO-8859-1 (\xb0 is the degree character in that encoding, but an invalid character in UTF-8, which is the de-facto standard these days). Signed-off-by: Johannes Schindelin --- block-vvfat.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/block-vvfat.c b/block-vvfat.c index 1ac4472..1104cea 100644 --- a/block-vvfat.c +++ b/block-vvfat.c @@ -1242,14 +1242,14 @@ static void print_direntry(const direntry_t* direntry) int j = 0; char buffer[1024]; - fprintf(stderr, "direntry 0x%x: ", (int)direntry); + fprintf(stderr, "direntry %p: ", direntry); if(!direntry) return; if(is_long_name(direntry)) { unsigned char* c=(unsigned char*)direntry; int i; for(i=1;i<11 && c[i] && c[i]!=0xff;i+=2) -#define ADD_CHAR(c) {buffer[j] = (c); if (buffer[j] < ' ') buffer[j] = 0xb0; j++;} +#define ADD_CHAR(c) buffer[j++] = (c) ? '.' : (c) ADD_CHAR(c[i]); for(i=14;i<26 && c[i] && c[i]!=0xff;i+=2) ADD_CHAR(c[i]); @@ -1271,7 +1271,7 @@ static void print_direntry(const direntry_t* direntry) static void print_mapping(const mapping_t* mapping) { - fprintf(stderr, "mapping (0x%x): begin, end = %d, %d, dir_index = %d, first_mapping_index = %d, name = %s, mode = 0x%x, " , (int)mapping, mapping->begin, mapping->end, mapping->dir_index, mapping->first_mapping_index, mapping->path, mapping->mode); + fprintf(stderr, "mapping (%p): begin, end = %d, %d, dir_index = %d, first_mapping_index = %d, name = %s, mode = 0x%x, " , mapping, mapping->begin, mapping->end, mapping->dir_index, mapping->first_mapping_index, mapping->path, mapping->mode); if (mapping->mode & MODE_DIRECTORY) fprintf(stderr, "parent_mapping_index = %d, first_dir_index = %d\n", mapping->info.dir.parent_mapping_index, mapping->info.dir.first_dir_index); else @@ -2843,7 +2843,7 @@ static void checkpoint(void) { return; /* avoid compiler warnings: */ hexdump(NULL, 100); - remove_mapping(vvv, NULL); + remove_mapping(vvv, 0); print_mapping(NULL); print_direntry(NULL); } -- 1.6.0.4.1189.g8876f