qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [6023] Use a hex value instead of possibly ambiguous 8


From: Johannes Schindelin
Subject: Re: [Qemu-devel] [6023] Use a hex value instead of possibly ambiguous 8 bit character
Date: Sun, 14 Dec 2008 11:54:02 +0100 (CET)
User-agent: Alpine 1.00 (DEB 882 2007-12-20)

Hi,

On Sun, 14 Dec 2008, Blue Swirl wrote:

> On 12/14/08, Johannes Schindelin <address@hidden> 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 <address@hidden>
---
 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]