From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KYo1H-0008TE-7r for qemu-devel@nongnu.org; Thu, 28 Aug 2008 16:23:03 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KYo1E-0008S0-U3 for qemu-devel@nongnu.org; Thu, 28 Aug 2008 16:23:01 -0400 Received: from [199.232.76.173] (port=39485 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KYo1E-0008Rs-BG for qemu-devel@nongnu.org; Thu, 28 Aug 2008 16:23:00 -0400 Received: from an-out-0708.google.com ([209.85.132.243]:16943) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KYo1D-0007r1-Rj for qemu-devel@nongnu.org; Thu, 28 Aug 2008 16:23:00 -0400 Received: by an-out-0708.google.com with SMTP id d18so87835and.130 for ; Thu, 28 Aug 2008 13:22:57 -0700 (PDT) Message-ID: <48B708F1.9080300@codemonkey.ws> Date: Thu, 28 Aug 2008 15:22:09 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] [RESEND] wrap up use of dangerous ctype.h macros References: <18364.21555.874570.784725@mariner.uk.xensource.com> <18614.56999.66982.389605@mariner.uk.xensource.com> In-Reply-To: <18614.56999.66982.389605@mariner.uk.xensource.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Ian Jackson wrote: > The macros isupper, isspace, tolower, and so forth (from ) > 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