git: bcee560d390e - main - libucl: Const correctness for C23

Lexi Winter <[email protected]> Mon, 03 Aug 2026 14:30:42 +0000
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a70a612.37216.46f0d6fb__19095.5568965123$1785767479$gmane$org@gitrepo.freebsd.org>
The branch main has been updated by ivy:

URL: https://cgit.FreeBSD.org/src/commit/?id=bcee560d390eb8aa8fd0f08a7a0bffb6e77fffc6

commit bcee560d390eb8aa8fd0f08a7a0bffb6e77fffc6
Author:     Lexi Winter <[email protected]>
AuthorDate: 2026-08-03 14:05:09 +0000
Commit:     Lexi Winter <[email protected]>
CommitDate: 2026-08-03 14:05:09 +0000

    libucl: Const correctness for C23
    
    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 libucl during
    the bootstrap build, since it assumes the return value is always
    a mutable pointer.
    
    Instead of assigning directly to params->prefix (which is const),
    use a non-const temporary variable and assign the result after
    we've done the modification.
    
    MFC after:      1 week
    Reviewed by:    bofh, bapt
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D58490
---
 contrib/libucl/src/ucl_util.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/contrib/libucl/src/ucl_util.c b/contrib/libucl/src/ucl_util.c
index a56d8b27ad65..3b732a58701c 100644
--- a/contrib/libucl/src/ucl_util.c
+++ b/contrib/libucl/src/ucl_util.c
@@ -1088,7 +1088,7 @@ ucl_include_file_single(const unsigned char *data, size_t len,
 	bool res;
 	struct ucl_chunk *chunk;
 	unsigned char *buf = NULL;
-	char *old_curfile, *ext;
+	char *old_curfile, *ext, *tmp;
 	size_t buflen = 0;
 	char filebuf[PATH_MAX], realbuf[PATH_MAX];
 	int prev_state;
@@ -1200,12 +1200,13 @@ ucl_include_file_single(const unsigned char *data, size_t len,
 
 	if (params->use_prefix && params->prefix == NULL) {
 		/* Auto generate a key name based on the included filename */
-		params->prefix = basename(realbuf);
-		ext = strrchr(params->prefix, '.');
+		tmp = basename(realbuf);
+		ext = strrchr(tmp, '.');
 		if (ext != NULL && (strcmp(ext, ".conf") == 0 || strcmp(ext, ".ucl") == 0)) {
 			/* Strip off .conf or .ucl */
 			*ext = '\0';
 		}
+		params->prefix = tmp;
 	}
 	if (params->prefix != NULL) {
 		/* This is a prefixed include */