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

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

Yann E. MORIN
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/