Yo Greg!

On Sun, 01 Nov 2026 07:54:46 -0500
Greg Troxel <[email protected]> wrote:

> "Gary E. Miller" <[email protected]> writes:
> > Been that way since POSIX.1-2008.  
> 
> Yes, but you didn't quote enough.  It says:
> 
>   The c argument is a type int, the value of which the application
> shall ensure is a character representable as an unsigned char or
> equal to the value of the macro EOF. If the argument has any other
> value, the behavior is undefined.

GNU libc hhas no such caveat.  C99 also does not.

C23 doe say:

"In all cases the argument is an int, the value of which shall be
representable as an unsigned char or shall equal the value of the macro
EOF. If the argument has any other value, the behavior is undefined. "

Since gpsd only passed a char or unsigned char to isXXXX(), that is
satisfied.  Those are simply promoted to int, so need no cast.

> This leads to the general rule that you can't use arguments of type
> char for ctype functions.  If it's a char, it needs to be cast to
> unsigned char.   There are a massive number of such constructions
> already in the code.

Id be happy to ensure gpsd is always using uchar for anything going
to isXXXXX();  Old gpsd code is very sloppy about char vs uchar.

> A quick grep pulls out a bunch; there are 187 casts to unsigned char
> and most of them are for ctype; I delete a few lines from the below
> block that were casts not immediately in a ctype call.

>   libgps/gpsutils.c:    if (isdigit((unsigned char)*p)) {

Yeah, those are just wrong.  I did not expect to get them all
on the first pass.  I'll rip those out today.

RGDS
GARY
---------------------------------------------------------------------------
Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703
        [email protected]  Tel:+1 541 382 8588

            Veritas liberabit vos. -- Quid est veritas?
    "If you can't measure it, you can't improve it." - Lord Kelvin

Attachment: pgp5z6mxOG1_V.pgp
Description: OpenPGP digital signature

Reply via email to