Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/common/lib/libc/gen Add code to protect the ptree from multi...
details: https://anonhg.NetBSD.org/src/rev/361dc60fa4ea
branches: trunk
changeset: 780185:361dc60fa4ea
user: matt <matt%NetBSD.org@localhost>
date: Sat Jul 14 18:16:54 2012 +0000
description:
Add code to protect the ptree from multiple insertions of the same node.
diffstat:
common/lib/libc/gen/ptree.c | 18 +++++++++++++++---
1 files changed, 15 insertions(+), 3 deletions(-)
diffs (53 lines):
diff -r 3677c027e9df -r 361dc60fa4ea common/lib/libc/gen/ptree.c
--- a/common/lib/libc/gen/ptree.c Sat Jul 14 17:12:27 2012 +0000
+++ b/common/lib/libc/gen/ptree.c Sat Jul 14 18:16:54 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ptree.c,v 1.7 2012/07/13 01:15:27 matt Exp $ */
+/* $NetBSD: ptree.c,v 1.8 2012/07/14 18:16:54 matt Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
#include <sys/types.h>
#include <sys/systm.h>
#include <lib/libkern/libkern.h>
-__KERNEL_RCSID(0, "$NetBSD: ptree.c,v 1.7 2012/07/13 01:15:27 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ptree.c,v 1.8 2012/07/14 18:16:54 matt Exp $");
#else
#include <stddef.h>
#include <stdint.h>
@@ -53,7 +53,7 @@
#else
#define KASSERT(e) do { } while (/*CONSTCOND*/ 0)
#endif
-__RCSID("$NetBSD: ptree.c,v 1.7 2012/07/13 01:15:27 matt Exp $");
+__RCSID("$NetBSD: ptree.c,v 1.8 2012/07/14 18:16:54 matt Exp $");
#endif /* _KERNEL || _STANDALONE */
#ifdef _LIBC
@@ -459,6 +459,12 @@
pt_insertdata_t id;
/*
+ * If this node already exists in the tree, return failure.
+ */
+ if (target == PT_NODE(pt->pt_root))
+ return false;
+
+ /*
* We need a leaf so we can match against. Until we get a leaf
* we having nothing to test against.
*/
@@ -480,6 +486,12 @@
id.id_node = *id.id_insertp;
/*
+ * If this node already exists in the tree, return failure.
+ */
+ if (target == ptn)
+ return false;
+
+ /*
* If we hit a leaf, try to insert target at leaf. We could
* have inlined ptree_insert_leaf here but that would have
* made this routine much harder to understand. Trust the
Home |
Main Index |
Thread Index |
Old Index