git: cb2daf8ce116 - main - rpcgen: Const correctness for C23

Lexi Winter <[email protected]> Mon, 03 Aug 2026 14:30:41 +0000
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a70a611.362bf.2e839682__29780.1027468935$1785767471$gmane$org@gitrepo.freebsd.org>
The branch main has been updated by ivy:

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

commit cb2daf8ce116d475597d7ab95f2454ea54c968e6
Author:     Lexi Winter <[email protected]>
AuthorDate: 2026-08-03 14:04:16 +0000
Commit:     Lexi Winter <[email protected]>
CommitDate: 2026-08-03 14:04:16 +0000

    rpcgen: 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 rpcgen during
    the bootstrap build, since it assumes the return value is always
    a mutable pointer.
    
    For mkfile_output(), the pointed-to value is never modified, so
    fix this by making the pointer const as well.
    
    For open_log_file(), the current code modifies the supposedly const
    value in-place to remove the filename suffix, which happens to work
    but is wrong even in older versions of C.  Change the code to use a
    printf "%.*s" format specifier to strip the suffix instead.
    
    MFC after:      1 week
    Reviewed by:    brooks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D58489
---
 usr.bin/rpcgen/rpc_main.c   |  3 ++-
 usr.bin/rpcgen/rpc_svcout.c | 19 +++++++++++++------
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/usr.bin/rpcgen/rpc_main.c b/usr.bin/rpcgen/rpc_main.c
index 8d5afad86cff..4c69be1ed333 100644
--- a/usr.bin/rpcgen/rpc_main.c
+++ b/usr.bin/rpcgen/rpc_main.c
@@ -868,7 +868,8 @@ static void mkfile_output(struct commandline *cmd)
 {
 	const char *mkfilename, *clientname, *clntname, *xdrname, *hdrname;
 	const char *servername, *svcname, *servprogname, *clntprogname;
-	char *temp, *mkftemp;
+	const char *temp;
+	char *mkftemp;
 
 	svcname = file_name(cmd->infile, "_svc.c");
 	clntname = file_name(cmd->infile, "_clnt.c");
diff --git a/usr.bin/rpcgen/rpc_svcout.c b/usr.bin/rpcgen/rpc_svcout.c
index 2c6849714d75..bbeed976c2d2 100644
--- a/usr.bin/rpcgen/rpc_svcout.c
+++ b/usr.bin/rpcgen/rpc_svcout.c
@@ -31,6 +31,7 @@
  * rpc_svcout.c, Server-skeleton outputter for the RPC protocol compiler
  * Copyright (C) 1987, Sun Microsystems, Inc.
  */
+#include <limits.h>
 #include <stdio.h>
 #include <string.h>
 #include "rpc_parse.h"
@@ -931,14 +932,20 @@ write_rpc_svc_fg(const char *infile, const char *sp)
 static void
 open_log_file(const char *infile, const char *sp)
 {
-	char *s;
+	const char *s;
 
 	s = strrchr(infile, '.');
-	if (s)
-		*s = '\0';
-	f_print(fout, "%sopenlog(\"%s\", LOG_PID, LOG_DAEMON);\n", sp, infile);
-	if (s)
-		*s = '.';
+	if (s) {
+		size_t len;
+
+		len = s - infile;
+		if (len > INT_MAX)
+			len = INT_MAX;
+		f_print(fout, "%sopenlog(\"%.*s\", LOG_PID, LOG_DAEMON);\n",
+		    sp, (int)len, infile);
+	} else
+		f_print(fout, "%sopenlog(\"%s\", LOG_PID, LOG_DAEMON);\n",
+		    sp, infile);
 }