xentrace: build fix
PATCH 1/1 xentrace: build fix
Hi!
Attached patch fixes warnings:
"array subscript has type 'char'"
Signature · 6 lines
---to satisfy European Law for business letters: Advanced Micro Devices GmbH Einsteinring 24, 85609 Dornach b. Muenchen Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632
tools/xentrace/xenctx.c +3 -3
@@ -178,12 +178,12 @@ static void read_symbol_table(const char/* need more checks for syntax here... */ symbol->address =strtoull (line, &p,16 ); -if (!isspace (*p++)) +if (!isspace ((uint8_t )*p++))continue ; type = *p++; -if (!isalpha (type) && type !='?' ) +if (!isalpha ((uint8_t )type) && type !='?' )continue ; -if (!isspace (*p++)) +if (!isspace ((uint8_t )*p++))continue ;/* in the future we should handle the module name
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Christoph Egger
Attached patch fixes warnings:
"array subscript has type 'char'"
May I ask with what kind of broken ctype.h you encountered this? It should be very natural to pass a plain 'char' to the is...() functions, and it looks rather broken to have these casts in there.
Thanks, Jan
Quoted 8 lines · On Wednesday 19 January 2011 15:11:28 Jan Beulich wrote:
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Christoph Egger
Attached patch fixes warnings:
"array subscript has type 'char'"May I ask with what kind of broken
ctype.hyou encountered this? It should be very natural to pass a plain 'char' to the is...() functions, and it looks rather broken to have these casts in there.
This has already been discussed on this list. Please read this thread:
http://lists.xensource.com/archives/html/xen-devel/2007-09/msg00447.html
Christoph
Signature · 6 lines
---to satisfy European Law for business letters: Advanced Micro Devices GmbH Einsteinring 24, 85609 Dornach b. Muenchen Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632
Jan Beulich writes ("Re: [Xen-devel] [PATCH] xentrace: build fix"):
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Christoph Egger
Attached patch fixes warnings:
"array subscript has type 'char'"May I ask with what kind of broken
ctype.hyou encountered this? It should be very natural to pass a plain 'char' to the is...() functions, and it looks rather broken to have these casts in there.
I'm afraid you're wrong. You are right that it "_should_ be very natural", but "should be " is not the same as "is" and in fact passing an arbitrary char to isfoobar() can have undefined behaviour.
Here is the SuS page for isspace:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/isspace.html
It says:
The c argument is an int, the value of which the application shall ensure is a character representable as an unsigned char or equal to the value of the macro EOF. If the argument has any other value, the behavior is undefined.
This a convoluted way of saying that passing a negative value other than EOF to isfoobar is allowed to crash. That can happen if char is signed (as it usually is) whenever a high-bit-set character (nowadays, utf-8) is found.
This means that the natural and "obviously correct" use of the ctype macros,
char c = some_unknown_string[n];
if (isspace(c)) { ...
is wrong.
The correct usage (assuming c cannot possibly be EOF) is:
if (isspace((unsigned char)c)) { ...
Yes, this is horrid but it is a requirement of the specification.
Many projects have a standard CTYPE macro which allows you to write
if (CTYPE(isspace,c)) { ...
Xen (particularly the external parts of stubdom) is absolutely full of bugs of this kind but most of them aren't all that problematic because the characters in question come from trusted sources like the Xen command line or domain config file or whatever.
My grep found this:
xen/include/acpi/platform/acenv.h:#define ACPI_IS_SPACE(i) isspace((int) (i))
which is a way of disabling the warning while continuing to have the bug.
NB, Christoph, the correct usage does not generally involve uint8_t (although in a Xen context where unsigned char is guaranteed to be the same size as uint8_t we don't care that much).
Ian.