Module Name:    src
Committed By:   rillig
Date:           Sat Aug 22 14:54:48 UTC 2020

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

Log Message:
make(1): add strict argument checks for Lst_InsertBefore

As with the other modifying operations on lists, the callers already
made sure that the arguments are valid.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/make/lst.c
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/make/lst.h
cvs rdiff -u -r1.115 -r1.116 src/usr.bin/make/make.c
cvs rdiff -u -r1.104 -r1.105 src/usr.bin/make/suff.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/make/lst.c
diff -u src/usr.bin/make/lst.c:1.25 src/usr.bin/make/lst.c:1.26
--- src/usr.bin/make/lst.c:1.25	Sat Aug 22 14:39:12 2020
+++ src/usr.bin/make/lst.c	Sat Aug 22 14:54:48 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.25 2020/08/22 14:39:12 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.26 2020/08/22 14:54:48 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.25 2020/08/22 14:39:12 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.26 2020/08/22 14:54:48 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.25 2020/08/22 14:39:12 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.26 2020/08/22 14:54:48 rillig Exp $");
 #endif /* not lint */
 #endif
 
@@ -192,7 +192,7 @@ Lst_Destroy(Lst list, FreeProc *freeProc
 
 /* Insert a new node with the given piece of data before the given node in the
  * given list. */
-ReturnStatus
+static ReturnStatus
 Lst_InsertBefore(Lst list, LstNode node, void *datum)
 {
     LstNode newNode;
@@ -230,6 +230,32 @@ Lst_InsertBefore(Lst list, LstNode node,
     return SUCCESS;
 }
 
+/* Insert a new node with the given piece of data before the given node in the
+ * given list. */
+void
+Lst_InsertBeforeS(Lst list, LstNode node, void *datum)
+{
+    LstNode newNode;
+
+    assert(LstIsValid(list));
+    assert(!LstIsEmpty(list));
+    assert(LstNodeIsValid(node));
+    assert(datum != NULL);
+
+    newNode = LstNodeNew(datum);
+    newNode->prev = node->prev;
+    newNode->next = node;
+
+    if (node->prev != NULL) {
+	node->prev->next = newNode;
+    }
+    node->prev = newNode;
+
+    if (node == list->first) {
+	list->first = newNode;
+    }
+}
+
 /* Insert a new node with the given piece of data after the given node in the
  * given list. */
 ReturnStatus

Index: src/usr.bin/make/lst.h
diff -u src/usr.bin/make/lst.h:1.31 src/usr.bin/make/lst.h:1.32
--- src/usr.bin/make/lst.h:1.31	Sat Aug 22 14:39:12 2020
+++ src/usr.bin/make/lst.h	Sat Aug 22 14:54:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lst.h,v 1.31 2020/08/22 14:39:12 rillig Exp $	*/
+/*	$NetBSD: lst.h,v 1.32 2020/08/22 14:54:48 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -114,7 +114,7 @@ Boolean		Lst_IsEmpty(Lst);
  * Functions to modify a list
  */
 /* Insert an element before another */
-ReturnStatus	Lst_InsertBefore(Lst, LstNode, void *);
+void		Lst_InsertBeforeS(Lst, LstNode, void *);
 /* Insert an element after another */
 ReturnStatus	Lst_InsertAfter(Lst, LstNode, void *);
 /* Place an element at the front of a lst. */

Index: src/usr.bin/make/make.c
diff -u src/usr.bin/make/make.c:1.115 src/usr.bin/make/make.c:1.116
--- src/usr.bin/make/make.c:1.115	Sat Aug 22 14:39:12 2020
+++ src/usr.bin/make/make.c	Sat Aug 22 14:54:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.c,v 1.115 2020/08/22 14:39:12 rillig Exp $	*/
+/*	$NetBSD: make.c,v 1.116 2020/08/22 14:54:48 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: make.c,v 1.115 2020/08/22 14:39:12 rillig Exp $";
+static char rcsid[] = "$NetBSD: make.c,v 1.116 2020/08/22 14:54:48 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)make.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: make.c,v 1.115 2020/08/22 14:39:12 rillig Exp $");
+__RCSID("$NetBSD: make.c,v 1.116 2020/08/22 14:54:48 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1015,7 +1015,7 @@ MakeBuildChild(void *v_cn, void *toBeMad
     if (toBeMade_next == NULL)
 	Lst_AppendS(toBeMade, cn);
     else
-	Lst_InsertBefore(toBeMade, toBeMade_next, cn);
+	Lst_InsertBeforeS(toBeMade, toBeMade_next, cn);
 
     if (cn->unmade_cohorts != 0)
 	Lst_ForEach(cn->cohorts, MakeBuildChild, toBeMade_next);

Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.104 src/usr.bin/make/suff.c:1.105
--- src/usr.bin/make/suff.c:1.104	Sat Aug 22 14:39:12 2020
+++ src/usr.bin/make/suff.c	Sat Aug 22 14:54:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.104 2020/08/22 14:39:12 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.105 2020/08/22 14:54:48 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.104 2020/08/22 14:39:12 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.105 2020/08/22 14:54:48 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)suff.c	8.4 (Berkeley) 3/21/94";
 #else
-__RCSID("$NetBSD: suff.c,v 1.104 2020/08/22 14:39:12 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.105 2020/08/22 14:54:48 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -522,7 +522,7 @@ SuffInsert(Lst l, Suff *s)
 	if (DEBUG(SUFF)) {
 	    fprintf(debug_file, "before %s(%d)\n", s2->name, s2->sNum);
 	}
-	(void)Lst_InsertBefore(l, ln, s);
+	Lst_InsertBeforeS(l, ln, s);
 	s->refCount++;
 	Lst_AppendS(s->ref, l);
     } else if (DEBUG(SUFF)) {
@@ -1646,7 +1646,7 @@ SuffExpandChildren(LstNode cln, GNode *p
 		fprintf(debug_file, "%s...", gn->name);
 	    }
 	    /* Add gn to the parents child list before the original child */
-	    (void)Lst_InsertBefore(pgn->children, cln, gn);
+	    Lst_InsertBeforeS(pgn->children, cln, gn);
 	    Lst_AppendS(gn->parents, pgn);
 	    pgn->unmade++;
 	    /* Expand wildcards on new node */
@@ -1701,7 +1701,7 @@ SuffExpandWildcards(LstNode cln, GNode *
 	gn = Targ_FindNode(cp, TARG_CREATE);
 
 	/* Add gn to the parents child list before the original child */
-	(void)Lst_InsertBefore(pgn->children, cln, gn);
+	Lst_InsertBeforeS(pgn->children, cln, gn);
 	Lst_AppendS(gn->parents, pgn);
 	pgn->unmade++;
     }

Reply via email to