This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] ctype functions and signedness


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




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]