Page MenuHomeFreeBSD

localedef: Const correctness for C23
AcceptedPublic

Authored by ivy on Jul 27 2026, 11:04 PM.
Tags
None
Referenced Files
F170550708: D58496.id182860.diff
Sat, Sep 5, 9:04 AM
F170537394: D58496.diff
Sat, Sep 5, 7:29 AM
F170476916: D58496.id185144.diff
Sat, Sep 5, 12:24 AM
F170420585: D58496.id185144.diff
Fri, Sep 4, 6:18 PM
F170413427: D58496.id185144.diff
Fri, Sep 4, 5:26 PM
Unknown Object (File)
Fri, Sep 4, 6:28 AM
Unknown Object (File)
Thu, Sep 3, 11:51 PM
Unknown Object (File)
Thu, Sep 3, 4:10 PM
Subscribers

Details

Reviewers
markj
des
kevans
Summary

On some platforms, e.g. Linux Clang 22.1.8 / glibc 2.43, strchr()
now implements the C23 behaviour where passing a const pointer to
strchr() also returns a const pointer. This breaks localedef during
the bootstrap build, since it assumes the return value is always
a mutable pointer.

This code can modify either a const (rodata) string, which happens
to be avoided by accident, or modify const global data. Change the
logic to instead create a local copy of the string and modify that
if needed. This introduces an additional allocation, but this is
not performance-sensitive code.

MFC after: 1 week
Sponsored by: The FreeBSD Foundation

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 75191
Build 72074: arc lint + arc unit

Event Timeline

ivy requested review of this revision.Jul 27 2026, 11:04 PM

I think it'd be cleaner to drop the const qualifier from yesstr/nostr/yesexpr/noexpr and use strdup() to assign the empty string in this function. But this works too.

This revision is now accepted and ready to land.Jul 28 2026, 1:29 PM

i was trying to avoid adding extra allocations for this group of patches, but i suppose this is not a performance-critical code path, so i'll switch it to use strdup if we think that's neater (i tend to agree, since __DECONST is at least a code smell).

use strdup() instead of __DECONST

This revision now requires review to proceed.Wed, Aug 26, 10:48 AM
This revision is now accepted and ready to land.Wed, Aug 26, 1:25 PM