Module Name:    src
Committed By:   rillig
Date:           Wed Aug 11 20:48:16 UTC 2021

Modified Files:
        src/usr.bin/mkdep: findcc.c

Log Message:
mkdep: document possible undefined behavior

If findcc is called with a constant string, as its prototype suggests,
the process crashes with a segmentation fault.  Luckily, neither mkdep
nor lint do that, but the function prototype is nevertheless confusing.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/mkdep/findcc.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.6 src/usr.bin/mkdep/findcc.c:1.7
--- src/usr.bin/mkdep/findcc.c:1.6	Sun Sep  4 20:30:06 2011
+++ src/usr.bin/mkdep/findcc.c	Wed Aug 11 20:48:16 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: findcc.c,v 1.6 2011/09/04 20:30:06 joerg Exp $ */
+/* $NetBSD: findcc.c,v 1.7 2021/08/11 20:48:16 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.6 2011/09/04 20:30:06 joerg Exp $");
+__RCSID("$NetBSD: findcc.c,v 1.7 2021/08/11 20:48:16 rillig Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -55,6 +55,11 @@ findcc(const char *progname)
 	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';
 	}
 

Reply via email to