Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/mkdep mkdep: document possible undefined behavior



details:   https://anonhg.NetBSD.org/src/rev/edf3f0693881
branches:  trunk
changeset: 1022887:edf3f0693881
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Aug 11 20:48:16 2021 +0000

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

diffstat:

 usr.bin/mkdep/findcc.c |  9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diffs (30 lines):

diff -r 60205d5399ab -r edf3f0693881 usr.bin/mkdep/findcc.c
--- a/usr.bin/mkdep/findcc.c    Wed Aug 11 20:42:26 2021 +0000
+++ b/usr.bin/mkdep/findcc.c    Wed Aug 11 20:48:16 2021 +0000
@@ -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 @@
        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';
        }
 



Home | Main Index | Thread Index | Old Index