Module Name:    src
Committed By:   rillig
Date:           Sun Aug 23 10:53:27 UTC 2020

Modified Files:
        src/usr.bin/make: compat.c lst.c lst.h

Log Message:
make(1): handle special case of a list containing null pointers

GNode.commands is the only place in make where a list can contain null
pointers.  That's unexpected, and memory management in CompatRunCommand
looks suspicous enough to warrant extensive documentation.


To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/usr.bin/make/compat.c
cvs rdiff -u -r1.36 -r1.37 src/usr.bin/make/lst.c
cvs rdiff -u -r1.38 -r1.39 src/usr.bin/make/lst.h

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/make/compat.c
diff -u src/usr.bin/make/compat.c:1.126 src/usr.bin/make/compat.c:1.127
--- src/usr.bin/make/compat.c:1.126	Sat Aug 22 21:42:38 2020
+++ src/usr.bin/make/compat.c	Sun Aug 23 10:53:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat.c,v 1.126 2020/08/22 21:42:38 rillig Exp $	*/
+/*	$NetBSD: compat.c,v 1.127 2020/08/23 10:53:27 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: compat.c,v 1.126 2020/08/22 21:42:38 rillig Exp $";
+static char rcsid[] = "$NetBSD: compat.c,v 1.127 2020/08/23 10:53:27 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)compat.c	8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: compat.c,v 1.126 2020/08/22 21:42:38 rillig Exp $");
+__RCSID("$NetBSD: compat.c,v 1.127 2020/08/23 10:53:27 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -247,7 +247,7 @@ CompatRunCommand(void *cmdp, void *gnp)
 	return 0;
     }
     cmd = cmdStart;
-    Lst_ReplaceS(cmdNode, cmdStart);
+    LstNode_SetS(cmdNode, cmdStart);
 
     if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) {
         assert(ENDNode != NULL);
@@ -394,7 +394,9 @@ again:
     free(mav);
     free(bp);
 
-    Lst_ReplaceS(cmdNode, NULL);
+    /* XXX: Memory management looks suspicious here. */
+    /* XXX: Setting a list item to NULL is unexpected. */
+    LstNode_SetNullS(cmdNode);
 
 #ifdef USE_META
     if (useMeta) {

Index: src/usr.bin/make/lst.c
diff -u src/usr.bin/make/lst.c:1.36 src/usr.bin/make/lst.c:1.37
--- src/usr.bin/make/lst.c:1.36	Sat Aug 22 23:06:51 2020
+++ src/usr.bin/make/lst.c	Sun Aug 23 10:53:27 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.36 2020/08/22 23:06:51 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.37 2020/08/23 10:53:27 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -37,11 +37,11 @@
 #include "make.h"
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: lst.c,v 1.36 2020/08/22 23:06:51 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.37 2020/08/23 10:53:27 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.36 2020/08/22 23:06:51 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.37 2020/08/23 10:53:27 rillig Exp $");
 #endif /* not lint */
 #endif
 
@@ -302,11 +302,23 @@ Lst_RemoveS(Lst list, LstNode node)
 
 /* Replace the datum in the given node with the new datum. */
 void
-Lst_ReplaceS(LstNode node, void *datum)
+LstNode_SetS(LstNode node, void *datum)
 {
+    assert(LstNodeIsValid(node));
+    assert(datum != NULL);
+
     node->datum = datum;
 }
 
+/* Replace the datum in the given node to NULL. */
+void
+LstNode_SetNullS(LstNode node)
+{
+    assert(LstNodeIsValid(node));
+
+    node->datum = NULL;
+}
+
 
 /*
  * Node-specific functions

Index: src/usr.bin/make/lst.h
diff -u src/usr.bin/make/lst.h:1.38 src/usr.bin/make/lst.h:1.39
--- src/usr.bin/make/lst.h:1.38	Sat Aug 22 22:57:53 2020
+++ src/usr.bin/make/lst.h	Sun Aug 23 10:53:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lst.h,v 1.38 2020/08/22 22:57:53 rillig Exp $	*/
+/*	$NetBSD: lst.h,v 1.39 2020/08/23 10:53:27 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -120,7 +120,8 @@ void		Lst_AppendS(Lst, void *);
 /* Remove an element */
 void		Lst_RemoveS(Lst, LstNode);
 /* Replace a node with a new value */
-void		Lst_ReplaceS(LstNode, void *);
+void		LstNode_SetS(LstNode node, void *datum);
+void		LstNode_SetNullS(LstNode node);
 void		Lst_PrependAllS(Lst, Lst);
 void		Lst_AppendAllS(Lst, Lst);
 void		Lst_MoveAllS(Lst, Lst);

Reply via email to