isascii(3) macros and casts

Alejandro Colomar alx@kernel.org
Wed Dec 11 20:53:58 GMT 2024


Hi Paul,

On Wed, Dec 11, 2024 at 09:50:30PM +0100, Alejandro Colomar wrote:
> On Wed, Dec 11, 2024 at 12:42:13PM -0800, Paul Eggert wrote:
> > On 2024-12-11 12:38, Paul Eggert wrote:
> > >    #define isdigit(x) ((int) {x} - '0' <= 9u)
> > 
> > Oh, that should be
> > 
> >   #define isdigit(x) ((unsigned int) (int) {x} - '0' <= 9)
> 
> LGTM.
> 
> > 
> > to avoid problems with signed integer overflow.

On the other hand, calling isdigit() with anything that's not a valid
char or EOF (-1) is already UB (and IMO, should stay as UB), so the
first approach should be enough, no?

Cheers,
Alex


-- 
<https://www.alejandro-colomar.es/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20241211/c5f3f6dc/attachment.sig>


More information about the Libc-alpha mailing list