Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make(1): add strict argument checks for Lst_Ins...



details:   https://anonhg.NetBSD.org/src/rev/9da0d34072db
branches:  trunk
changeset: 975148:9da0d34072db
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 22 14:54:48 2020 +0000

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

diffstat:

 usr.bin/make/lst.c  |  34 ++++++++++++++++++++++++++++++----
 usr.bin/make/lst.h  |   4 ++--
 usr.bin/make/make.c |   8 ++++----
 usr.bin/make/suff.c |  12 ++++++------
 4 files changed, 42 insertions(+), 16 deletions(-)

diffs (171 lines):

diff -r ba23b5f9de33 -r 9da0d34072db usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Sat Aug 22 14:51:44 2020 +0000
+++ b/usr.bin/make/lst.c        Sat Aug 22 14:54:48 2020 +0000
@@ -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 @@
 
 /* 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 @@
     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
diff -r ba23b5f9de33 -r 9da0d34072db usr.bin/make/lst.h
--- a/usr.bin/make/lst.h        Sat Aug 22 14:51:44 2020 +0000
+++ b/usr.bin/make/lst.h        Sat Aug 22 14:54:48 2020 +0000
@@ -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 @@
  * 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. */
diff -r ba23b5f9de33 -r 9da0d34072db usr.bin/make/make.c
--- a/usr.bin/make/make.c       Sat Aug 22 14:51:44 2020 +0000
+++ b/usr.bin/make/make.c       Sat Aug 22 14:54:48 2020 +0000
@@ -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 @@
     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);
diff -r ba23b5f9de33 -r 9da0d34072db usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Sat Aug 22 14:51:44 2020 +0000
+++ b/usr.bin/make/suff.c       Sat Aug 22 14:54:48 2020 +0000
@@ -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 @@
        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 @@
                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 @@
        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++;
     }



Home | Main Index | Thread Index | Old Index