yuyz-cyber left a comment (kamailio/kamailio#4563)

You are correct that the prototype takes an int, but the value domain is 
strictly restricted.

The isalnum()/isalpha() argument must be either EOF or a value representable as 
unsigned char (0–255). Anything else is undefined behavior.

On platforms where char is signed, a raw byte like 0x80 stored in a char 
promotes to -128. If the code calls isalnum((int)*p), it passes -128. This is 
not EOF (-1) and not in the unsigned char range, so it triggers UB.

Casting to unsigned char forces the value into the 0–255 range, which is 
exactly what the ctype APIs require.

The GNU libc manual (v2.42) explicitly states this requirement:

"If the argument c is of type char, it must be cast to unsigned char, as in the 
following example: isalpha ((unsigned char) c);" Source: 
https://sourceware.org/glibc/manual/2.42/html_node/Classification-of-Characters.html

-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/4563#issuecomment-3783918607
You are receiving this because you are subscribed to this thread.

Message ID: <kamailio/kamailio/issues/4563/[email protected]>
_______________________________________________
Kamailio - Development Mailing List -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to