git: 9fd8f5e761ba - main - mkimg: Const correctness for C23

Lexi Winter <[email protected]> Mon, 03 Aug 2026 14:30:46 +0000
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a70a616.36aae.2eb32f30__24422.066628334$1785767604$gmane$org@gitrepo.freebsd.org>
The branch main has been updated by ivy:

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

commit 9fd8f5e761ba663c8e99eeff64c5a7fd7bcf1e05
Author:     Lexi Winter <[email protected]>
AuthorDate: 2026-08-03 14:08:13 +0000
Commit:     Lexi Winter <[email protected]>
CommitDate: 2026-08-03 14:08:13 +0000

    mkimg: 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 mkimg during
    the bootstrap build, since it assumes the return value is always
    a mutable pointer.
    
    Make the existing 'sep' pointer const to fix the first case, and
    for the second, introduce a new non-const pointer for strchr,
    since we do modify the result in that case.
    
    MFC after:      1 week
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D58493
---
 usr.bin/mkimg/mkimg.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/usr.bin/mkimg/mkimg.c b/usr.bin/mkimg/mkimg.c
index 4a288d66be81..e814b67b1186 100644
--- a/usr.bin/mkimg/mkimg.c
+++ b/usr.bin/mkimg/mkimg.c
@@ -248,7 +248,8 @@ static int
 parse_part(const char *spec)
 {
 	struct part *part;
-	char *sep;
+	const char *sep;
+	char *asep;
 	size_t len;
 	int error;
 
@@ -301,15 +302,14 @@ parse_part(const char *spec)
 		goto errout;
 	}
 
-	spec = part->alias;
-	sep = strchr(spec, '/');
-	if (sep != NULL) {
-		*sep++ = '\0';
-		if (strlen(part->alias) == 0 || strlen(sep) == 0) {
+	asep = strchr(part->alias, '/');
+	if (asep != NULL) {
+		*asep++ = '\0';
+		if (strlen(part->alias) == 0 || strlen(asep) == 0) {
 			error = EINVAL;
 			goto errout;
 		}
-		part->label = strdup(sep);
+		part->label = strdup(asep);
 		if (part->label == NULL) {
 			error = ENOMEM;
 			goto errout;