Page MenuHomeFreeBSD

localedef: Const correctness for C23
AcceptedPublic

Authored by ivy on Jul 27 2026, 11:04 PM.
Tags
None
Referenced Files
F174559431: D58496.id185144.diff
Sun, Oct 4, 4:08 AM
Unknown Object (File)
Sat, Oct 3, 8:58 PM
Unknown Object (File)
Sat, Oct 3, 9:12 AM
Unknown Object (File)
Thu, Oct 1, 1:11 PM
Unknown Object (File)
Thu, Oct 1, 1:11 PM
Unknown Object (File)
Thu, Oct 1, 7:45 AM
Unknown Object (File)
Mon, Sep 28, 2:51 PM
Unknown Object (File)
Wed, Sep 23, 2:26 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 76186
Build 73069: 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.Aug 26 2026, 10:48 AM
This revision is now accepted and ready to land.Aug 26 2026, 1:25 PM