Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin mkdep: fix prototype of findcc



details:   https://anonhg.NetBSD.org/src/rev/4410f29f2bb0
branches:  trunk
changeset: 1023030:4410f29f2bb0
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Aug 19 21:21:04 2021 +0000

description:
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.

diffstat:

 usr.bin/mkdep/findcc.c      |  11 +++--------
 usr.bin/mkdep/findcc.h      |   2 +-
 usr.bin/xlint/xlint/xlint.c |   9 +++++----
 3 files changed, 9 insertions(+), 13 deletions(-)

diffs (84 lines):

diff -r d97b6c469f3c -r 4410f29f2bb0 usr.bin/mkdep/findcc.c
--- a/usr.bin/mkdep/findcc.c    Thu Aug 19 21:13:58 2021 +0000
+++ b/usr.bin/mkdep/findcc.c    Thu Aug 19 21:21:04 2021 +0000
@@ -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 @@
 #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';
        }
 
diff -r d97b6c469f3c -r 4410f29f2bb0 usr.bin/mkdep/findcc.h
--- a/usr.bin/mkdep/findcc.h    Thu Aug 19 21:13:58 2021 +0000
+++ b/usr.bin/mkdep/findcc.h    Thu Aug 19 21:21:04 2021 +0000
@@ -1,3 +1,3 @@
 #define DEFAULT_CC             "cc"
 
-char *findcc(const char *);
+char *findcc(char *);
diff -r d97b6c469f3c -r 4410f29f2bb0 usr.bin/xlint/xlint/xlint.c
--- a/usr.bin/xlint/xlint/xlint.c       Thu Aug 19 21:13:58 2021 +0000
+++ b/usr.bin/xlint/xlint/xlint.c       Thu Aug 19 21:21:04 2021 +0000
@@ -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 @@
 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 @@
 
        /* 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);



Home | Main Index | Thread Index | Old Index