From c7fd916b674dacfe1c4bf6c1a4007393e9dd503e Mon Sep 17 00:00:00 2001 From: Andy Heninger <andyh@apache.org> Date: Mon, 22 May 2000 22:38:12 +0000 Subject: [PATCH] DOM: GetNodeById(), fixed bad problem with rehash operation that caused creashes. git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@172124 13f79535-47bb-0310-9956-ffa450edef68 --- src/dom/NodeIDMap.cpp | 8 ++++++++ src/dom/NodeVector.cpp | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/dom/NodeIDMap.cpp b/src/dom/NodeIDMap.cpp index 25863bcd3..c55650e99 100644 --- a/src/dom/NodeIDMap.cpp +++ b/src/dom/NodeIDMap.cpp @@ -58,6 +58,7 @@ #include "AttrImpl.hpp" #include "NodeIDMap.hpp" #include <util/XMLString.hpp> +#include <stdio.h> static const int gPrimes[] = {997, 9973, 99991, 999983, 0 }; // To do - add a few more. @@ -130,6 +131,8 @@ void NodeIDMap::add(AttrImpl *attr) tableSlot == (AttrImpl *)-1) break; currentHash += initalHash; // rehash + if (currentHash >= fSize) + currentHash = currentHash % fSize; } // @@ -175,6 +178,8 @@ void NodeIDMap::remove(AttrImpl *attr) } currentHash += initalHash; // rehash. + if (currentHash >= fSize) + currentHash = currentHash % fSize; } }; @@ -206,6 +211,8 @@ AttrImpl *NodeIDMap::find(const DOMString &id) return tableSlot; currentHash += initalHash; // rehash + if (currentHash >= fSize) + currentHash = currentHash % fSize; } return 0; // Never gets here, but keeps some compilers happy. }; @@ -224,6 +231,7 @@ void NodeIDMap::growTable() // // Figure the new table size. // + fprintf(stderr, "growing...\n"); fSizeIndex++; fSize = gPrimes[fSizeIndex]; if (fSize == 0) diff --git a/src/dom/NodeVector.cpp b/src/dom/NodeVector.cpp index fcdd3b5b5..0cba59729 100644 --- a/src/dom/NodeVector.cpp +++ b/src/dom/NodeVector.cpp @@ -56,6 +56,10 @@ /* * $Log$ + * Revision 1.6 2000/05/22 22:38:12 andyh + * DOM: GetNodeById(), fixed bad problem with rehash operation that caused + * creashes. + * * Revision 1.5 2000/03/28 19:43:13 roddey * Fixes for signed/unsigned warnings. New work for two way transcoding * stuff. @@ -140,6 +144,8 @@ void NodeVector::checkSpace() { NodeImpl *NodeVector::elementAt(unsigned int index) { + if (index >= nextFreeSlot) + return 0; return data[index]; }; -- GitLab