From: Anthony Liguori <anthony@codemonkey.ws>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] [RESEND] wrap up use of dangerous ctype.h macros
Date: Thu, 28 Aug 2008 15:22:09 -0500 [thread overview]
Message-ID: <48B708F1.9080300@codemonkey.ws> (raw)
In-Reply-To: <18614.56999.66982.389605@mariner.uk.xensource.com>
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
next prev parent reply other threads:[~2008-08-28 20:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-20 16:24 [Qemu-devel] [PATCH] wrap up use of dangerous ctype.h macros Ian Jackson
2008-08-28 17:21 ` [Qemu-devel] [PATCH] [RESEND] " Ian Jackson
2008-08-28 20:22 ` Anthony Liguori [this message]
2008-08-29 9:42 ` Ian Jackson
2008-09-07 2:49 ` Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48B708F1.9080300@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.