This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] ctype functions and signedness
- From: Jeff Law <law at redhat dot com>
- To: Michael McConville <mmcco at mykolab dot com>, gcc-patches at gcc dot gnu dot org
- Date: Tue, 24 Nov 2015 16:01:23 -0700
- Subject: Re: [PATCH] ctype functions and signedness
- Authentication-results: sourceware.org; auth=none
- References: <20151116155919 dot GA13057 at thinkpad dot swarthmore dot edu>
On 11/16/2015 08:59 AM, Michael McConville wrote:
Hi, everyone.
While it often (usually?) isn't an issue, passing a signed char to ctype
functions is undefined. Here's the CERT entry:
https://www.securecoding.cert.org/confluence/x/fAs
This means that we need to cast chars to unsigned char before passing
them to one of these functions.
The below patch, generated by a Coccinelle script, fixes instances of
this. It may need some minor tweaks to add line breaks and conform with
local style conventions.
The changes to the boehm-gc directory really should go to the upstream
project. I wouldn't be terribly surprised if boehm-gc for GCC gets
deprecated given the trajectory GCJ is on.
--- gcc/testsuite/gcc.dg/charset/builtin1.c
+++ /tmp/cocci-output-20442-6d79bd-builtin1.c
@@ -14,9 +14,9 @@ static int strA(void) { return 'A'; }
int
main(void)
{
- if (!isdigit('1'))
+ if (!isdigit((unsigned char)'1'))
abort();
- if (isdigit('A'))
+ if (isdigit((unsigned char)'A'))
abort();
if (!isdigit(str1()))
abort();
This change actually fails regression testing. We're using
-fexec-charset=IBM1047 (EBCDIC). So '1' is -15, turned into an unsigned
char, 241 and boom, it fails isdigit.
While I'm not terribly concerned about EBCDIC within GCC itself, it does
bring into question the changes for the testsuites & runtimes in particular.
Jeff