Module Name:    src
Committed By:   rillig
Date:           Fri Aug 21 04:09:12 UTC 2020

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

Log Message:
make(1): assert correct usage of the Lst_Open API

All calls to Lst_Next are properly protected by Lst_Open, so there is no
possible assertion failure here.


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/usr.bin/make/arch.c
cvs rdiff -u -r1.94 -r1.95 src/usr.bin/make/dir.c
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/lst.c
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/make/lst.h
cvs rdiff -u -r1.105 -r1.106 src/usr.bin/make/make.c
cvs rdiff -u -r1.98 -r1.99 src/usr.bin/make/suff.c
cvs rdiff -u -r1.65 -r1.66 src/usr.bin/make/targ.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/arch.c
diff -u src/usr.bin/make/arch.c:1.84 src/usr.bin/make/arch.c:1.85
--- src/usr.bin/make/arch.c:1.84	Fri Aug 21 02:20:47 2020
+++ src/usr.bin/make/arch.c	Fri Aug 21 04:09:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.84 2020/08/21 02:20:47 rillig Exp $	*/
+/*	$NetBSD: arch.c,v 1.85 2020/08/21 04:09:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.84 2020/08/21 02:20:47 rillig Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.85 2020/08/21 04:09:12 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)arch.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: arch.c,v 1.84 2020/08/21 02:20:47 rillig Exp $");
+__RCSID("$NetBSD: arch.c,v 1.85 2020/08/21 04:09:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1130,7 +1130,7 @@ Arch_MemMTime(GNode *gn)
 	gn->mtime = 0;
 	return 0;
     }
-    while ((ln = Lst_Next(gn->parents)) != NULL) {
+    while ((ln = Lst_NextS(gn->parents)) != NULL) {
 	pgn = (GNode *)Lst_Datum(ln);
 
 	if (pgn->type & OP_ARCHV) {

Index: src/usr.bin/make/dir.c
diff -u src/usr.bin/make/dir.c:1.94 src/usr.bin/make/dir.c:1.95
--- src/usr.bin/make/dir.c:1.94	Fri Aug 21 03:36:03 2020
+++ src/usr.bin/make/dir.c	Fri Aug 21 04:09:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.94 2020/08/21 03:36:03 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.95 2020/08/21 04:09:12 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: dir.c,v 1.94 2020/08/21 03:36:03 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.95 2020/08/21 04:09:12 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.94 2020/08/21 03:36:03 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.95 2020/08/21 04:09:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -509,7 +509,7 @@ Dir_SetPATH(void)
 		Var_Append(".PATH", cur->name, VAR_GLOBAL);
 	}
 
-	while ((ln = Lst_Next(dirSearchPath)) != NULL) {
+	while ((ln = Lst_NextS(dirSearchPath)) != NULL) {
 	    p = (Path *)Lst_Datum(ln);
 	    if (p == dotLast)
 		continue;
@@ -813,7 +813,7 @@ DirExpandInt(const char *word, Lst path,
     Path *p;			/* Directory in the node */
 
     if (Lst_Open(path) == SUCCESS) {
-	while ((ln = Lst_Next(path)) != NULL) {
+	while ((ln = Lst_NextS(path)) != NULL) {
 	    p = (Path *)Lst_Datum(ln);
 	    DirMatchFiles(word, p, expansions);
 	}
@@ -1185,7 +1185,7 @@ Dir_FindFile(const char *name, Lst path)
 	    return file;
 	}
 
-	while ((ln = Lst_Next(path)) != NULL) {
+	while ((ln = Lst_NextS(path)) != NULL) {
 	    p = (Path *)Lst_Datum(ln);
 	    if (p == dotLast)
 		continue;
@@ -1243,7 +1243,7 @@ Dir_FindFile(const char *name, Lst path)
 	}
 
 	(void)Lst_Open(path);
-	while ((ln = Lst_Next(path)) != NULL) {
+	while ((ln = Lst_NextS(path)) != NULL) {
 	    p = (Path *)Lst_Datum(ln);
 	    if (p == dotLast)
 		continue;
@@ -1301,7 +1301,7 @@ Dir_FindFile(const char *name, Lst path)
 	}
 
 	(void)Lst_Open(path);
-	while ((ln = Lst_Next(path)) != NULL) {
+	while ((ln = Lst_NextS(path)) != NULL) {
 	    p = (Path *)Lst_Datum(ln);
 	    if (p == dotLast)
 		continue;
@@ -1679,7 +1679,7 @@ Dir_MakeFlags(const char *flag, Lst path
     Buf_Init(&buf, 0);
 
     if (Lst_Open(path) == SUCCESS) {
-	while ((ln = Lst_Next(path)) != NULL) {
+	while ((ln = Lst_NextS(path)) != NULL) {
 	    Path *p = (Path *)Lst_Datum(ln);
 	    Buf_AddStr(&buf, " ");
 	    Buf_AddStr(&buf, flag);
@@ -1803,7 +1803,7 @@ Dir_PrintDirectories(void)
 	     hits * 100 / (hits + bigmisses + nearmisses) : 0));
     fprintf(debug_file, "# %-20s referenced\thits\n", "directory");
     if (Lst_Open(openDirectories) == SUCCESS) {
-	while ((ln = Lst_Next(openDirectories)) != NULL) {
+	while ((ln = Lst_NextS(openDirectories)) != NULL) {
 	    p = (Path *)Lst_Datum(ln);
 	    fprintf(debug_file, "# %-20s %10d\t%4d\n", p->name, p->refCount,
 		    p->hits);

Index: src/usr.bin/make/lst.c
diff -u src/usr.bin/make/lst.c:1.8 src/usr.bin/make/lst.c:1.9
--- src/usr.bin/make/lst.c:1.8	Fri Aug 21 03:36:03 2020
+++ src/usr.bin/make/lst.c	Fri Aug 21 04:09:12 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.8 2020/08/21 03:36:03 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.9 2020/08/21 04:09:12 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -38,11 +38,11 @@
 #include "make_malloc.h"
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: lst.c,v 1.8 2020/08/21 03:36:03 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.9 2020/08/21 04:09:12 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.8 2020/08/21 03:36:03 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.9 2020/08/21 04:09:12 rillig Exp $");
 #endif /* not lint */
 #endif
 
@@ -922,15 +922,13 @@ Lst_Open(Lst l)
  *-----------------------------------------------------------------------
  */
 LstNode
-Lst_Next(Lst l)
+Lst_NextS(Lst l)
 {
     ListNode tln;
     List list = l;
 
-    if ((LstValid(l) == FALSE) ||
-	(list->isOpen == FALSE)) {
-	return NULL;
-    }
+    assert(LstValid(l));
+    assert(list->isOpen);
 
     list->prevPtr = list->curPtr;
 

Index: src/usr.bin/make/lst.h
diff -u src/usr.bin/make/lst.h:1.24 src/usr.bin/make/lst.h:1.25
--- src/usr.bin/make/lst.h:1.24	Fri Aug 21 03:36:03 2020
+++ src/usr.bin/make/lst.h	Fri Aug 21 04:09:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lst.h,v 1.24 2020/08/21 03:36:03 rillig Exp $	*/
+/*	$NetBSD: lst.h,v 1.25 2020/08/21 04:09:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -168,7 +168,7 @@ int		Lst_ForEachFrom(Lst, LstNode, int (
 /* Open the list */
 ReturnStatus	Lst_Open(Lst);
 /* Next element please, or NULL */
-LstNode		Lst_Next(Lst);
+LstNode		Lst_NextS(Lst);
 /* Finish table access */
 void		Lst_Close(Lst);
 

Index: src/usr.bin/make/make.c
diff -u src/usr.bin/make/make.c:1.105 src/usr.bin/make/make.c:1.106
--- src/usr.bin/make/make.c:1.105	Fri Aug 21 03:36:03 2020
+++ src/usr.bin/make/make.c	Fri Aug 21 04:09:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.c,v 1.105 2020/08/21 03:36:03 rillig Exp $	*/
+/*	$NetBSD: make.c,v 1.106 2020/08/21 04:09:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: make.c,v 1.105 2020/08/21 03:36:03 rillig Exp $";
+static char rcsid[] = "$NetBSD: make.c,v 1.106 2020/08/21 04:09:12 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.105 2020/08/21 03:36:03 rillig Exp $");
+__RCSID("$NetBSD: make.c,v 1.106 2020/08/21 04:09:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -470,7 +470,7 @@ Make_HandleUse(GNode *cgn, GNode *pgn)
     }
 
     if (Lst_Open(cgn->children) == SUCCESS) {
-	while ((ln = Lst_Next(cgn->children)) != NULL) {
+	while ((ln = Lst_NextS(cgn->children)) != NULL) {
 	    GNode *tgn, *gn = (GNode *)Lst_Datum(ln);
 
 	    /*
@@ -725,7 +725,7 @@ Make_Update(GNode *cgn)
 
     /* Now mark all the parents as having one less unmade child */
     if (Lst_Open(parents) == SUCCESS) {
-	while ((ln = Lst_Next(parents)) != NULL) {
+	while ((ln = Lst_NextS(parents)) != NULL) {
 	    pgn = (GNode *)Lst_Datum(ln);
 	    if (DEBUG(MAKE))
 		fprintf(debug_file, "inspect parent %s%s: flags %x, "
@@ -828,7 +828,7 @@ Make_Update(GNode *cgn)
     if (Lst_Open(cgn->iParents) == SUCCESS) {
 	const char *cpref = Var_Value(PREFIX, cgn, &p1);
 
-	while ((ln = Lst_Next(cgn->iParents)) != NULL) {
+	while ((ln = Lst_NextS(cgn->iParents)) != NULL) {
 	    pgn = (GNode *)Lst_Datum(ln);
 	    if (pgn->flags & REMAKE) {
 		Var_Set(IMPSRC, cname, pgn);
@@ -1447,7 +1447,7 @@ Make_ProcessWait(Lst targs)
 
 	owln = Lst_First(pgn->children);
 	Lst_Open(pgn->children);
-	for (; (ln = Lst_Next(pgn->children)) != NULL; ) {
+	for (; (ln = Lst_NextS(pgn->children)) != NULL; ) {
 	    cgn = Lst_Datum(ln);
 	    if (cgn->type & OP_WAIT) {
 		/* Make the .WAIT node depend on the previous children */

Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.98 src/usr.bin/make/suff.c:1.99
--- src/usr.bin/make/suff.c:1.98	Fri Aug 21 03:36:03 2020
+++ src/usr.bin/make/suff.c	Fri Aug 21 04:09:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.98 2020/08/21 03:36:03 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.99 2020/08/21 04:09:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.98 2020/08/21 03:36:03 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.99 2020/08/21 04:09:12 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.98 2020/08/21 03:36:03 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.99 2020/08/21 04:09:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -502,7 +502,7 @@ SuffInsert(Lst l, Suff *s)
     if (Lst_Open(l) == FAILURE) {
 	return;
     }
-    while ((ln = Lst_Next(l)) != NULL) {
+    while ((ln = Lst_NextS(l)) != NULL) {
 	s2 = (Suff *)Lst_Datum(ln);
 	if (s2->sNum >= s->sNum) {
 	    break;
@@ -1076,7 +1076,7 @@ Suff_DoPaths(void)
     inIncludes = Lst_Init();
     inLibs = Lst_Init();
 
-    while ((ln = Lst_Next(sufflist)) != NULL) {
+    while ((ln = Lst_NextS(sufflist)) != NULL) {
 	s = (Suff *)Lst_Datum(ln);
 	if (!Lst_IsEmpty (s->searchPath)) {
 #ifdef INCLUDES
@@ -1301,7 +1301,7 @@ SuffRemoveSrc(Lst l)
 #endif
 
 
-    while ((ln = Lst_Next(l)) != NULL) {
+    while ((ln = Lst_NextS(l)) != NULL) {
 	s = (Src *)Lst_Datum(ln);
 	if (s->children == 0) {
 	    free(s->file);
@@ -1439,7 +1439,7 @@ SuffFindCmds(Src *targ, Lst slst)
     prefLen = strlen(targ->pref);
 
     for (;;) {
-	ln = Lst_Next(t->children);
+	ln = Lst_NextS(t->children);
 	if (ln == NULL) {
 	    Lst_Close(t->children);
 	    return NULL;

Index: src/usr.bin/make/targ.c
diff -u src/usr.bin/make/targ.c:1.65 src/usr.bin/make/targ.c:1.66
--- src/usr.bin/make/targ.c:1.65	Fri Aug 21 02:20:48 2020
+++ src/usr.bin/make/targ.c	Fri Aug 21 04:09:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: targ.c,v 1.65 2020/08/21 02:20:48 rillig Exp $	*/
+/*	$NetBSD: targ.c,v 1.66 2020/08/21 04:09:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: targ.c,v 1.65 2020/08/21 02:20:48 rillig Exp $";
+static char rcsid[] = "$NetBSD: targ.c,v 1.66 2020/08/21 04:09:12 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)targ.c	8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: targ.c,v 1.65 2020/08/21 02:20:48 rillig Exp $");
+__RCSID("$NetBSD: targ.c,v 1.66 2020/08/21 04:09:12 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -398,7 +398,7 @@ Targ_FindList(Lst names, int flags)
     if (Lst_Open(names) == FAILURE) {
 	return nodes;
     }
-    while ((ln = Lst_Next(names)) != NULL) {
+    while ((ln = Lst_NextS(names)) != NULL) {
 	name = (char *)Lst_Datum(ln);
 	gn = Targ_FindNode(name, flags);
 	if (gn != NULL) {

Reply via email to