Module Name: src
Committed By: rillig
Date: Thu Aug 19 21:21:04 UTC 2021
Modified Files:
src/usr.bin/mkdep: findcc.c findcc.h
src/usr.bin/xlint/xlint: xlint.c
Log Message:
mkdep: fix prototype of findcc
A function that modifies a string argument must not declare that
argument as 'const char *', even if all callers (mkdep and lint) always
pass it a modifiable string.
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/mkdep/findcc.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/mkdep/findcc.h
cvs rdiff -u -r1.77 -r1.78 src/usr.bin/xlint/xlint/xlint.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/mkdep/findcc.c
diff -u src/usr.bin/mkdep/findcc.c:1.7 src/usr.bin/mkdep/findcc.c:1.8
--- src/usr.bin/mkdep/findcc.c:1.7 Wed Aug 11 20:48:16 2021
+++ src/usr.bin/mkdep/findcc.c Thu Aug 19 21:21:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: findcc.c,v 1.7 2021/08/11 20:48:16 rillig Exp $ */
+/* $NetBSD: findcc.c,v 1.8 2021/08/19 21:21:04 rillig Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
#if !defined(lint)
__COPYRIGHT("@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\
All rights reserved.");
-__RCSID("$NetBSD: findcc.c,v 1.7 2021/08/11 20:48:16 rillig Exp $");
+__RCSID("$NetBSD: findcc.c,v 1.8 2021/08/19 21:21:04 rillig Exp $");
#endif /* not lint */
#include <sys/param.h>
@@ -49,17 +49,12 @@ __RCSID("$NetBSD: findcc.c,v 1.7 2021/08
#include "findcc.h"
char *
-findcc(const char *progname)
+findcc(char *progname)
{
char *path, *dir, *next;
char buffer[MAXPATHLEN];
if ((next = strchr(progname, ' ')) != NULL) {
- /*
- * FIXME: writing to a 'const char *' invokes undefined
- * behavior. The call to 'strchr' subtly hides the unconst
- * cast from the compiler.
- */
*next = '\0';
}
Index: src/usr.bin/mkdep/findcc.h
diff -u src/usr.bin/mkdep/findcc.h:1.1 src/usr.bin/mkdep/findcc.h:1.2
--- src/usr.bin/mkdep/findcc.h:1.1 Fri Jun 14 23:14:18 2002
+++ src/usr.bin/mkdep/findcc.h Thu Aug 19 21:21:04 2021
@@ -1,3 +1,3 @@
#define DEFAULT_CC "cc"
-char *findcc(const char *);
+char *findcc(char *);
Index: src/usr.bin/xlint/xlint/xlint.c
diff -u src/usr.bin/xlint/xlint/xlint.c:1.77 src/usr.bin/xlint/xlint/xlint.c:1.78
--- src/usr.bin/xlint/xlint/xlint.c:1.77 Thu Aug 19 16:29:41 2021
+++ src/usr.bin/xlint/xlint/xlint.c Thu Aug 19 21:21:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: xlint.c,v 1.77 2021/08/19 16:29:41 rillig Exp $ */
+/* $NetBSD: xlint.c,v 1.78 2021/08/19 21:21:04 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: xlint.c,v 1.77 2021/08/19 16:29:41 rillig Exp $");
+__RCSID("$NetBSD: xlint.c,v 1.78 2021/08/19 21:21:04 rillig Exp $");
#endif
#include <sys/param.h>
@@ -612,9 +612,10 @@ main(int argc, char *argv[])
static void
fname(const char *name)
{
+ static char default_cc[] = DEFAULT_CC;
const char *bn, *suff;
char **args, *ofn, *pathname;
- const char *CC;
+ char *CC;
size_t len;
int fd;
@@ -661,7 +662,7 @@ fname(const char *name)
/* run cc */
if ((CC = getenv("CC")) == NULL)
- CC = DEFAULT_CC;
+ CC = default_cc;
if ((pathname = findcc(CC)) == NULL)
if (setenv("PATH", DEFAULT_PATH, 1) == 0)
pathname = findcc(CC);