From e703ba7bc19f95b6b8d3fb02e7724b88f6233ef6 Mon Sep 17 00:00:00 2001 From: "waterson%netscape.com" Date: Fri, 31 Mar 2000 03:52:55 +0000 Subject: [PATCH] Fix off-by-one error that could occur if you try to inspect an RDF container during renumbering. --- rdf/base/src/nsRDFContainer.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/rdf/base/src/nsRDFContainer.cpp b/rdf/base/src/nsRDFContainer.cpp index ff38cdf11246..ccc234a4f08e 100644 --- a/rdf/base/src/nsRDFContainer.cpp +++ b/rdf/base/src/nsRDFContainer.cpp @@ -549,6 +549,14 @@ RDFContainerImpl::Renumber(PRInt32 aStartIndex, PRInt32 aIncrement) rv = GetCount(&count); if (NS_FAILED(rv)) return rv; + if (aIncrement > 0) { + // Update the container's nextVal to reflect the + // renumbering. We do this now if aIncrement > 0 because we'll + // want to be able to acknowledge that new elements are in the + // container. + rv = SetNextValue(count + aIncrement + 1); + if (NS_FAILED(rv)) return rv; + } PRInt32 i; if (aIncrement < 0) { @@ -604,9 +612,14 @@ RDFContainerImpl::Renumber(PRInt32 aStartIndex, PRInt32 aIncrement) i -= aIncrement; } - // Update the container's nextVal to reflect the renumbering - rv = SetNextValue(count + aIncrement + 1); - if (NS_FAILED(rv)) return rv; + if (aIncrement < 0) { + // Update the container's nextVal to reflect the + // renumbering. We do this now if aIncrement < 0 because, up + // until this point, we'll want people to be able to find + // things that are still "at the end". + rv = SetNextValue(count + aIncrement + 1); + if (NS_FAILED(rv)) return rv; + } return NS_OK; }