Module Name: src Committed By: rillig Date: Sat Aug 22 15:43:32 UTC 2020
Modified Files: src/usr.bin/make: compat.c dir.c job.c lst.c lst.h make.c suff.c Log Message: make(1): require argument of Lst_Member to be non-null Since the lists don't contain null pointers, it doesn't make sense to search for a null pointer. All calls but one already had obviously non-null arguments. The one remaining call using targ->suff has been guarded for now. The code for Lst_Member became much simpler than before. Partly because the old code had an extra condition for circular lists, which are not used by make. To generate a diff of this commit: cvs rdiff -u -r1.123 -r1.124 src/usr.bin/make/compat.c cvs rdiff -u -r1.103 -r1.104 src/usr.bin/make/dir.c cvs rdiff -u -r1.211 -r1.212 src/usr.bin/make/job.c cvs rdiff -u -r1.28 -r1.29 src/usr.bin/make/lst.c cvs rdiff -u -r1.34 -r1.35 src/usr.bin/make/lst.h cvs rdiff -u -r1.117 -r1.118 src/usr.bin/make/make.c cvs rdiff -u -r1.106 -r1.107 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/compat.c diff -u src/usr.bin/make/compat.c:1.123 src/usr.bin/make/compat.c:1.124 --- src/usr.bin/make/compat.c:1.123 Sat Aug 22 14:39:12 2020 +++ src/usr.bin/make/compat.c Sat Aug 22 15:43:32 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: compat.c,v 1.123 2020/08/22 14:39:12 rillig Exp $ */ +/* $NetBSD: compat.c,v 1.124 2020/08/22 15:43:32 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.123 2020/08/22 14:39:12 rillig Exp $"; +static char rcsid[] = "$NetBSD: compat.c,v 1.124 2020/08/22 15:43:32 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.123 2020/08/22 14:39:12 rillig Exp $"); +__RCSID("$NetBSD: compat.c,v 1.124 2020/08/22 15:43:32 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -232,7 +232,7 @@ CompatRunCommand(void *cmdp, void *gnp) errCheck = !(gn->type & OP_IGNORE); doIt = FALSE; - cmdNode = Lst_Member(gn->commands, cmd); + cmdNode = Lst_MemberS(gn->commands, cmd); cmdStart = Var_Subst(cmd, gn, VARE_WANTRES); /* @@ -538,7 +538,7 @@ Compat_Make(void *gnp, void *pgnp) goto cohorts; } - if (Lst_Member(gn->iParents, pgn) != NULL) { + if (Lst_MemberS(gn->iParents, pgn) != NULL) { char *p1; Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn); bmake_free(p1); @@ -642,7 +642,7 @@ Compat_Make(void *gnp, void *pgnp) */ pgn->flags &= ~REMAKE; } else { - if (Lst_Member(gn->iParents, pgn) != NULL) { + if (Lst_MemberS(gn->iParents, pgn) != NULL) { char *p1; Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn); bmake_free(p1); Index: src/usr.bin/make/dir.c diff -u src/usr.bin/make/dir.c:1.103 src/usr.bin/make/dir.c:1.104 --- src/usr.bin/make/dir.c:1.103 Sat Aug 22 15:17:09 2020 +++ src/usr.bin/make/dir.c Sat Aug 22 15:43:32 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: dir.c,v 1.103 2020/08/22 15:17:09 rillig Exp $ */ +/* $NetBSD: dir.c,v 1.104 2020/08/22 15:43:32 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.103 2020/08/22 15:17:09 rillig Exp $"; +static char rcsid[] = "$NetBSD: dir.c,v 1.104 2020/08/22 15:43:32 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.103 2020/08/22 15:17:09 rillig Exp $"); +__RCSID("$NetBSD: dir.c,v 1.104 2020/08/22 15:43:32 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -417,7 +417,7 @@ Dir_InitDot(void) LstNode ln; /* Remove old entry from openDirectories, but do not destroy. */ - ln = Lst_Member(openDirectories, dot); + ln = Lst_MemberS(openDirectories, dot); Lst_RemoveS(openDirectories, ln); } @@ -1574,7 +1574,7 @@ Dir_AddDir(Lst path, const char *name) ln = Lst_Find(openDirectories, name, DirFindName); if (ln != NULL) { p = Lst_DatumS(ln); - if (path && Lst_Member(path, p) == NULL) { + if (path && Lst_MemberS(path, p) == NULL) { p->refCount += 1; Lst_AppendS(path, p); } @@ -1702,7 +1702,7 @@ Dir_Destroy(void *pp) if (p->refCount == 0) { LstNode ln; - ln = Lst_Member(openDirectories, p); + ln = Lst_MemberS(openDirectories, p); Lst_RemoveS(openDirectories, ln); Hash_DeleteTable(&p->files); @@ -1764,7 +1764,7 @@ Dir_Concat(Lst path1, Lst path2) for (ln = Lst_First(path2); ln != NULL; ln = Lst_Succ(ln)) { p = Lst_DatumS(ln); - if (Lst_Member(path1, p) == NULL) { + if (Lst_MemberS(path1, p) == NULL) { p->refCount += 1; Lst_AppendS(path1, p); } Index: src/usr.bin/make/job.c diff -u src/usr.bin/make/job.c:1.211 src/usr.bin/make/job.c:1.212 --- src/usr.bin/make/job.c:1.211 Sat Aug 22 13:28:20 2020 +++ src/usr.bin/make/job.c Sat Aug 22 15:43:32 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: job.c,v 1.211 2020/08/22 13:28:20 rillig Exp $ */ +/* $NetBSD: job.c,v 1.212 2020/08/22 15:43:32 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: job.c,v 1.211 2020/08/22 13:28:20 rillig Exp $"; +static char rcsid[] = "$NetBSD: job.c,v 1.212 2020/08/22 15:43:32 rillig Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: job.c,v 1.211 2020/08/22 13:28:20 rillig Exp $"); +__RCSID("$NetBSD: job.c,v 1.212 2020/08/22 15:43:32 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -714,8 +714,8 @@ JobPrintCommand(void *cmdp, void *jobp) if (strcmp(cmd, "...") == 0) { job->node->type |= OP_SAVE_CMDS; if ((job->flags & JOB_IGNDOTS) == 0) { - job->tailCmds = Lst_Succ(Lst_Member(job->node->commands, - cmd)); + LstNode dotsNode = Lst_MemberS(job->node->commands, cmd); + job->tailCmds = Lst_Succ(dotsNode); return 1; } return 0; Index: src/usr.bin/make/lst.c diff -u src/usr.bin/make/lst.c:1.28 src/usr.bin/make/lst.c:1.29 --- src/usr.bin/make/lst.c:1.28 Sat Aug 22 15:17:09 2020 +++ src/usr.bin/make/lst.c Sat Aug 22 15:43:32 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: lst.c,v 1.28 2020/08/22 15:17:09 rillig Exp $ */ +/* $NetBSD: lst.c,v 1.29 2020/08/22 15:43:32 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.28 2020/08/22 15:17:09 rillig Exp $"; +static char rcsid[] = "$NetBSD: lst.c,v 1.29 2020/08/22 15:43:32 rillig Exp $"; #else #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: lst.c,v 1.28 2020/08/22 15:17:09 rillig Exp $"); +__RCSID("$NetBSD: lst.c,v 1.29 2020/08/22 15:43:32 rillig Exp $"); #endif /* not lint */ #endif @@ -519,24 +519,18 @@ Lst_FindFrom(Lst list, LstNode node, con /* Return the first node that contains the given datum, or NULL. */ LstNode -Lst_Member(Lst list, void *datum) +Lst_MemberS(Lst list, void *datum) { LstNode node; - if (list == NULL) { - return NULL; - } - node = list->first; - if (node == NULL) { - return NULL; - } + assert(LstIsValid(list)); + assert(datum != NULL); - do { + for (node = list->first; node != NULL; node = node->next) { if (node->datum == datum) { return node; } - node = node->next; - } while (node != NULL && node != list->first); + } return NULL; } Index: src/usr.bin/make/lst.h diff -u src/usr.bin/make/lst.h:1.34 src/usr.bin/make/lst.h:1.35 --- src/usr.bin/make/lst.h:1.34 Sat Aug 22 15:17:09 2020 +++ src/usr.bin/make/lst.h Sat Aug 22 15:43:32 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: lst.h,v 1.34 2020/08/22 15:17:09 rillig Exp $ */ +/* $NetBSD: lst.h,v 1.35 2020/08/22 15:43:32 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -155,7 +155,7 @@ LstNode Lst_FindFrom(Lst, LstNode, cons * See if the given datum is on the list. Returns the LstNode containing * the datum */ -LstNode Lst_Member(Lst, void *); +LstNode Lst_MemberS(Lst, void *); /* Apply a function to all elements of a lst */ int Lst_ForEach(Lst, int (*)(void *, void *), void *); /* Apply a function to all elements of a lst starting from a certain point. */ Index: src/usr.bin/make/make.c diff -u src/usr.bin/make/make.c:1.117 src/usr.bin/make/make.c:1.118 --- src/usr.bin/make/make.c:1.117 Sat Aug 22 15:17:09 2020 +++ src/usr.bin/make/make.c Sat Aug 22 15:43:32 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: make.c,v 1.117 2020/08/22 15:17:09 rillig Exp $ */ +/* $NetBSD: make.c,v 1.118 2020/08/22 15:43:32 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: make.c,v 1.117 2020/08/22 15:17:09 rillig Exp $"; +static char rcsid[] = "$NetBSD: make.c,v 1.118 2020/08/22 15:43:32 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.117 2020/08/22 15:17:09 rillig Exp $"); +__RCSID("$NetBSD: make.c,v 1.118 2020/08/22 15:43:32 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -525,7 +525,7 @@ MakeHandleUse(void *cgnp, void *pgnp) * children the parent has. This is used by Make_Run to decide * whether to queue the parent or examine its children... */ - if ((ln = Lst_Member(pgn->children, cgn)) != NULL) { + if ((ln = Lst_MemberS(pgn->children, cgn)) != NULL) { Lst_RemoveS(pgn->children, ln); pgn->unmade--; } Index: src/usr.bin/make/suff.c diff -u src/usr.bin/make/suff.c:1.106 src/usr.bin/make/suff.c:1.107 --- src/usr.bin/make/suff.c:1.106 Sat Aug 22 15:17:09 2020 +++ src/usr.bin/make/suff.c Sat Aug 22 15:43:32 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: suff.c,v 1.106 2020/08/22 15:17:09 rillig Exp $ */ +/* $NetBSD: suff.c,v 1.107 2020/08/22 15:43:32 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: suff.c,v 1.106 2020/08/22 15:17:09 rillig Exp $"; +static char rcsid[] = "$NetBSD: suff.c,v 1.107 2020/08/22 15:43:32 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.106 2020/08/22 15:17:09 rillig Exp $"); +__RCSID("$NetBSD: suff.c,v 1.107 2020/08/22 15:43:32 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -407,7 +407,7 @@ SuffUnRef(void *lp, void *sp) { Lst l = (Lst) lp; - LstNode ln = Lst_Member(l, sp); + LstNode ln = Lst_MemberS(l, sp); if (ln != NULL) { Lst_RemoveS(l, ln); ((Suff *)sp)->refCount--; @@ -1303,7 +1303,7 @@ SuffRemoveSrc(Lst l) free(s->pref); else { #ifdef DEBUG_SRC - LstNode ln2 = Lst_Member(s->parent->cp, s); + LstNode ln2 = Lst_MemberS(s->parent->cp, s); if (ln2 != NULL) Lst_RemoveS(s->parent->cp, ln2); #endif @@ -1474,7 +1474,9 @@ SuffFindCmds(Src *targ, Lst slst) */ suff = Lst_DatumS(ln); - if (Lst_Member(suff->parents, targ->suff) != NULL) + /* XXX: Can targ->suff be NULL here? */ + if (targ->suff != NULL && + Lst_MemberS(suff->parents, targ->suff) != NULL) break; } @@ -1669,7 +1671,7 @@ SuffExpandChildren(LstNode cln, GNode *p */ pgn->unmade--; Lst_RemoveS(pgn->children, cln); - Lst_RemoveS(cgn->parents, Lst_Member(cgn->parents, pgn)); + Lst_RemoveS(cgn->parents, Lst_MemberS(cgn->parents, pgn)); } static void @@ -1721,7 +1723,7 @@ SuffExpandWildcards(LstNode cln, GNode * */ pgn->unmade--; Lst_RemoveS(pgn->children, cln); - Lst_RemoveS(cgn->parents, Lst_Member(cgn->parents, pgn)); + Lst_RemoveS(cgn->parents, Lst_MemberS(cgn->parents, pgn)); } /*- @@ -2311,7 +2313,7 @@ sfnd_abort: * up to, but not including, the parent node. */ while (bottom && bottom->parent != NULL) { - if (Lst_Member(slst, bottom) == NULL) { + if (Lst_MemberS(slst, bottom) == NULL) { Lst_AppendS(slst, bottom); } bottom = bottom->parent; @@ -2387,7 +2389,7 @@ sfnd_abort: */ sfnd_return: if (bottom) - if (Lst_Member(slst, bottom) == NULL) + if (Lst_MemberS(slst, bottom) == NULL) Lst_AppendS(slst, bottom); while (SuffRemoveSrc(srcs) || SuffRemoveSrc(targs))