On Sat, Nov 16, 2024 at 10:21:47PM +0100, Patrice Dumas wrote:
> Hello,
> 
> On cygwin, there are warnings for the isalpha and similar functions from
> ctype.h, like:
> 
> ../../info/indices.c: In function 'index_entry_matches':
> ../../info/indices.c:297:30: warning: array subscript has type 'char' 
> [-Wchar-subscripts]
>    297 |           else if (!isdigit (*p))
>        |                              ^~
> ../../info/indices.c: In function 'report_index_match':
> ../../info/indices.c:433:29: warning: array subscript has type 'char' 
> [-Wchar-subscripts]
>   433 |       upper = isupper (match[start]) ? 1 : 0;
>       |                        ~~~~~^~~~~~~
> 
> Seems to happen when the implementation of isupper/isalpha... is an
> array, and somewhat because is* functions argument is supposed to be
> unsigned char.  In the glibc manual it is indeed recommended to cast
> char to (unsigned char) when calling the functions.
> 
> Is it important?  Should we cast?

I don't remember for certain but we already cast to unsigned char
in the call to isspace in xspara.c.

2022-04-14  Gavin Smith  <gavinsmith0...@gmail.com>

        unsigned char for isspace

        * tp/Texinfo/XS/parsetexi/end_line.c (end_line_misc_line),
        * tp/Texinfo/XS/xspara.c (xspara_add_text):
        Cast argument to isspace to unsigned char.  This avoids varying
        test results on Solaris 10 and 11.

The Linux man pages state ("man isalpha"):

      The standards require that the argument c for these functions is either
       EOF or a value that is representable in the type unsigned char.  If the
       argument c is of type char, it must be cast to unsigned char, as in the
       following example:

           char c;
           ...
           res = toupper((unsigned char) c);

       This is necessary because char may be the equivalent of signed char, in
       which case a byte where the top bit is set would be sign extended  when
       converting  to  int,  yielding a value that is outside the range of un‐
       signed char.

It may not matter much in practice but I expect that it would be ok to
put the casts in.


Reply via email to