qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH] [RESEND] wrap up use of dangerous ctype.h macro


From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH] [RESEND] wrap up use of dangerous ctype.h macros
Date: Thu, 28 Aug 2008 15:22:09 -0500
User-agent: Thunderbird 2.0.0.16 (X11/20080723)

Ian Jackson wrote:
The macros isupper, isspace, tolower, and so forth (from <ctype.h>)
are defined to take an int containing the value of an unsigned char,
or EOF.

This means that you mustn't write:
   char *p;
   ...
   if (isspace(*p)) { ...

If *p is a top-bit-set character, and your host architecture has
signed chars by default (most do), then the result is passing a
negative number to isspace, which is not allowed.  glibc permits this
but not all libcs do, and it is wrong according to C89 and C99.

The correct use is:
   if (isspace((unsigned char)*p)) { ...

This is rather unweildy and error-prone so I in the attached patch
have invented a CTYPE macro which takes some but not all of the pain
out of it.

Can't we just have qemu_isspace() macros? I find the CTYPE macro quite awkward. I don't think most people are comfortable with that kind of syntax.

Regards,

Anthony Liguori




reply via email to

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