[bug #57930] plain char arguments to <ctype.h> functions

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[bug #57930] plain char arguments to <ctype.h> functions

anonymous
URL:
  <https://savannah.gnu.org/bugs/?57930>

                 Summary: plain char arguments to <ctype.h> functions
                 Project: make
            Submitted by: None
            Submitted on: Sun 01 Mar 2020 01:10:01 PM UTC
                Severity: 3 - Normal
              Item Group: None
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
       Component Version: None
        Operating System: None
           Fixed Release: None
           Triage Status: None

    _______________________________________________________

Details:

Building git head currently fails because of an ancient sin: passing plain
char arguments to functions from <ctype.h>.  E.g. this happens on Cygwin with
GCC 9.2:

  CC       src/load.o
In file included from src/makeint.h:75,
                 from src/load.c:17:
src/load.c: In function 'load_file':
src/load.c:198:23: error: array subscript has type 'char'
[-Werror=char-subscripts]
  198 |       while (isalnum (*fp) || *fp == '_')
      |                       ^~~
cc1: all warnings being treated as errors

The argument to these function/macros is formally an int, holding either a
value from the range of unsigned char, or EOF.  Plain char might be signed,
which is unsuitable for this usage.

So everywhere a plain char is passed to isalpha(), isspace() etc., it has to
be cast to (unsigned char) first.

Please note that the above is not the only one in the source that is wrong in
this regard.  It's just the only one active in this particular build.




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57930>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57930] plain char arguments to <ctype.h> functions

anonymous
Update of bug #57930 (project make):

                  Status:                    None => Fixed                  
             Assigned to:                    None => psmith                
             Open/Closed:                    Open => Closed                
       Component Version:                    None => 4.0                    
           Fixed Release:                    None => SCM                    
           Triage Status:                    None => Small Effort          

    _______________________________________________________

Follow-up Comment #1:

Besides the issue in load.c there were only two places where the cast was
missing: one in the implementations of strcasecmp / strcasencmp which are only
needed on systems that don't provide any case-insensitive comparison natively,
and secondly in a bunch of VMS code.  I don't know if VMS even does
UTF/Unicode.

I fixed them all anyway; thanks for the note.

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57930>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/