Re: [PATCH] wip: change ISSPACE to use ascii whitespace check.

Alejandro Colomar via Mutt-dev <[email protected]>
Newsgroups gmane.mail.mutt.devel
Message-ID <aZZbm_pklTfoJMrB@devuan>
Hi Ian,

On 2026-02-18T23:42:28+0000, Ian Collier via Mutt-dev wrote:
> On Wed, Feb 18, 2026 at 09:58:24PM +0000, Crystal Kolipe via Mutt-dev wrote:
> > On Wed, Feb 18, 2026 at 03:29:57PM +0100, Alejandro Colomar via Mutt-dev wrote:
> > > 	#define isspace_c(c)            (!streq(strchrnul(MUTT_CTYPE_SPACE_C, c), ""))
> > > 	#define isspace_rfc5322_fws(c)  (!streq(strchrnul(MUTT_CTYPE_RFC5322_FWS, c), ""))
> 
> > Note that strchrnul() is not available natively on OpenBSD.
> 
> I do not understand why strchrnul and strcmp are even being invoked here.

Because they are necessary.  (Well, strcmp(3) is not, as you could do
manual byte operations, but it's simple, more readable, and optimized
out.)  strchrnul(3) is necessary.

> 
> Yes, strchrnul(str,c) will be not equal to "" iff c is in the string, and
> yes the C compiler will probably optimize out the strcmp call, but isn't
> 
> NULL != strchr(str,c) 
> 
> easier and shorter?

	strchr(s, '\0') != NULL

would evaluate to true, which is a misbehavior: it would treat '\0' as
white space, while it is not.  But

	!streq(strchrnul(s, '\0'), "")

would work correctly, evaluating to false.

See <https://github.com/shadow-maint/shadow/pull/1471>.

> (And apparently more portable.)

Apparently, some libc implementations make it difficult to implement
isspace()-like APIs correctly.

> 
> imc


Have a lovely night!
Alex

-- 
<https://www.alejandro-colomar.es>
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmmWXWMACgkQ64mZXMKQ
wqkj3g//fVVEQkaFbAafFGv+yfZHx+HCAOIqWkGh/0pf7cnzHwfaBhp0LLGDJNj4
Fv1PDSTrkznabcloMEa2Tvr4RyeUzq/dglNDCpA3XeoR5Q8YyyODkl/gCdX27Ym9
T4ek784uJsTYGyNCnK4xjUPsgdqdSaxKR9w5t7KZ3jdEeAPy4NxWEGb/KDggoxIp
LMSIcQdI9p64ePemgrxgPalmEwjYbTeyyw3iFQ8wELoS9KS++34JHi6f9QPu74WR
OhrxrDi3pErV2Q0QvOu3BqDI4FGn9mvZX2xXEM3wNqqfokS/7zIvjBoVhtSr/17w
K4oNspZBbvtytSrWehp7QHU4WucBt0wxwubXMuQNTUsFGx6cDRLH7Vl1f1yar/0d
5QL608aO3XRl1lRI6I8DElz1anP9cIogRqmk3g/0XUYoLDeXnUTjusrh3YvYFN3H
XBqtyAP2Rdec7tKFy4Yd3ADGnb0wT08SpMuYpJQdKdZK5vAsZJoqRayYSVJt0kAz
+azN21QBB5PC9pWiAreNxCh5D6oOPBGwn8ZrUz+O5tCab0juxAs3eoybpVVvmYuj
f+qIa6h5/422XgDDFt/BaRA6Q9Z4/Y2XPF5EP/MdHwrTlOrOp/QSuvL2EKtwlfS2
4W295WKxZCOkz24M3Ca9oxYd5QxDC8U9KlhRT+hL58ZhcnDwlpw=
=oC8Q
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.