[6023] Use a hex value instead of possibly ambiguous 8 bit character
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
Modified Paths:
--------------
trunk/block-vvfat.c
Modified: trunk/block-vvfat.c
===================================================================
block-vvfat.c +1 -1
@@ -1249,7 +1249,7 @@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] = '\xB0'; j++;} +#define ADD_CHAR (c) {buffer[j] = (c); if (buffer[j] < ' ') buffer[j] = 0xb0; j++;}ADD_CHAR (c[i]);for (i=14 ;i<26 && c[i] && c[i]!=0xff ;i+=2 )ADD_CHAR (c[i]);
Hi,
Quoted 8 lines · Blue Swirl
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.
Besides...
block-vvfat.c line 1252
Quoted 6 lines
block-vvfat.c +1
-1@@ -1249,7 +1249,7 @@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] = '\xB0'; j++;} +#define ADD_CHAR (c) {buffer[j] = (c); if (buffer[j] < ' ') buffer[j] = 0xb0; j++;}
in the meantime I think it would be more readable as
#define ADD_CHAR(c) buffer[j++] = (c) < ' ' ? '\xb0' : 'c';
Note that
- this code is only ever reached when DEBUG is defined, and
- this code still assumes that your terminal is ISO-8859-1, which is typically wrong these days (UTF-8 is the de-facto standard).
Ciao,
Dscho
Quoted 10 lines · Johannes Schindelin
Hi,
Quoted 5 lines · Blue Swirl
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)
Quoted 7 lines
Quoted 3 lines
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. 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. 0xb0 will not ever cause these problems, '\xb0' could work too.
Quoted 13 lines
Besides...
block-vvfat.c line 1252
Quoted 6 lines
block-vvfat.c +1
-1@@ -1249,7 +1249,7 @@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] = '\xB0'; j++;} +#define ADD_CHAR (c) {buffer[j] = (c); if (buffer[j] < ' ') buffer[j] = 0xb0; j++;}in the meantime I think it would be more readable as
Quoted 8 lines
#define
ADD_CHAR(c)buffer[j++] = (c) < ' ' ? '\xb0' : 'c';Note that
- this code is only ever reached when DEBUG is defined, and
- this code still assumes that your terminal is ISO-8859-1, which is typically wrong these days (UTF-8 is the de-facto standard).
Patches welcome :)
Hi,
Quoted 14 lines · Blue Swirl
Quoted 12 lines · Johannes Schindelin
Quoted 8 lines · Blue Swirl
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
Quoted 5 lines
Quoted 2 lines
/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.
Quoted 3 lines
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.
Quoted 1 line
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).
--- block-vvfat.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
block-vvfat.c +4 -4
@@ -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 ); }
Signature · 1 line
1.6.0.4.1189.g8876f
Quoted 1 line · Johannes Schindelin
+#define
ADD_CHAR(c)buffer[j++] = (c) ? '.' : (c)
isprint(c) perhaps?
Andreas.
Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected] SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Hi,
Please Cc: me, I only did not miss your message because it is a slow Sunday morning (_and_ I am not in a deep hacking session).
Quoted 3 lines · Andreas Schwab
Quoted 1 line · Johannes Schindelin
+#define
ADD_CHAR(c)buffer[j++] = (c) ? '.' : (c)
Oops. This is obviously wrong, and should read
#define ADD_CHAR(c) buffer[j++] = (c) < ' ' ? '.' : (c)
Quoted 1 line
isprint(c) perhaps?
I vote against using isprint(c). The code is simple as it is, otherwise you'd have to look up what isprint() does, _and_ rely on isprint() being present.
I know, there are many people on this list who are all too happy to rely on new-fangled C99 stuff or lock themselves (and others) in with GCCisms. Peronally, though, I find it utterly stupid to do that unless you really have to.
Ciao,
Dscho
Quoted 8 lines · Johannes Schindelin
I vote against using isprint(c). The code is simple as it is, otherwise you'd have to look up what
isprint()does, _and_ rely onisprint()being present.I know, there are many people on this list who are all too happy to rely on new-fangled C99 stuff or lock themselves (and others) in with GCCisms. Peronally, though, I find it utterly stupid to do that unless you really have to.
isprint is part of C89 and any compiler less than 20 years old should support it.
Erik
Signature · 4 lines
----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- Complex problems have simple easy to understand wrong answers.
Hi,
Please Cc: me if you reply directly to me.
Quoted 6 lines · Erik de Castro Lopo
Quoted 4 lines · Johannes Schindelin
I vote against using isprint(c). The code is simple as it is, otherwise you'd have to look up what
isprint()does, _and_ rely onisprint()being present.
Quoted 7 lines
Quoted 4 lines
I know, there are many people on this list who are all too happy to rely on new-fangled C99 stuff or lock themselves (and others) in with GCCisms. Peronally, though, I find it utterly stupid to do that unless you really have to.
isprint is part of C89 and any compiler less than 20 years old should support it.
Okay, so it is C89. So what does it do exactly? Yes, exactly you have to look it up. Nice job.
Whatever,
Dscho
P.S.: oh, so now the umlauts are not even printed when you are on an ISO-8859-1 console? Nice job, again.
Quoted 29 lines · Johannes Schindelin
Hi,
Quoted 15 lines · Blue Swirl
Quoted 12 lines · Johannes Schindelin
Quoted 8 lines · Blue Swirl
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 characterQuoted 5 lines
Quoted 2 lines
/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.
Quoted 7 lines
Quoted 3 lines
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.
Sizeof(char) has nothing to do with this. But if 0xb0 is invalid in UTF-8, then we have nothing to worry, at least until the next invention comes along.
Quoted 19 lines · Johannes Schindelin
Hi,
Please Cc: me, I only did not miss your message because it is a slow Sunday morning (_and_ I am not in a deep hacking session).
Quoted 3 lines · Andreas Schwab
Quoted 1 line · Johannes Schindelin
+#define
ADD_CHAR(c)buffer[j++] = (c) ? '.' : (c)Oops. This is obviously wrong, and should read
Quoted 8 lines
#define
ADD_CHAR(c)buffer[j++] = (c) < ' ' ? '.' : (c)Quoted 1 line
isprint(c) perhaps?
I vote against using isprint(c). The code is simple as it is, otherwise
you'd have to look up whatisprint()does, _and_ rely onisprint()being present.
I agree that we should not use plain old isprint, but instead the highly advanced, omnipresent qemu_isprint which has none of the problems of what isprint may have. ;-)
In message: <[email protected]>
Erik de Castro Lopo <[email protected]> writes:
: Johannes Schindelin wrote:
:
: > I vote against using isprint(c). The code is simple as it is, otherwise : > you'd have to look up what isprint() does, _and_ rely on isprint() being : > present.
: >
: > I know, there are many people on this list who are all too happy to rely : > on new-fangled C99 stuff or lock themselves (and others) in with GCCisms. : > Peronally, though, I find it utterly stupid to do that unless you really : > have to.
:
: isprint is part of C89 and any compiler less than 20 years old should : support it.
isprint() also was in many K&R compilers, but that was system dependent. The VAX I used in college in 1985 had it, as did the 'C' compiler for my DEC Rainbow and the TOPS-20 C compiler written at my university...
Warner
Quoted 11 lines · Johannes Schindelin
Quoted 2 lines
isprint is part of C89 and any compiler less than 20 years old should support it.
Okay, so it is C89. So what does it do exactly? Yes, exactly you have to look it up. Nice job.
Whatever,
Dscho
P.S.: oh, so now the umlauts are not even printed when you are on an ISO-8859-1 console? Nice job, again.
isprint should return true for umlaut characters on an ISO-8859-1 console, provided the locale ($LANG, $LC_CTYPE) matches the console.
The question is whether you want QEMU's debugging output to depend on the current locale, or be the same for everyone. If the former, isprint is quite appropriate. If the latter, restricting to ASCII is appropriate.
-- Jamie