From d631159edf246c04c87f8639c691ac55430b9272 Mon Sep 17 00:00:00 2001 From: "buster%netscape.com" Date: Sun, 19 Sep 1999 23:47:04 +0000 Subject: [PATCH] fixed an error where the out param was not being initialized to null. This could cause an error in the caller if the caller fails to check the return code as well as the pointer!=null before dereferencing the result. git-svn-id: svn://10.0.0.236/trunk@48285 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/base/EditAggregateTxn.cpp | 7 +++++++ mozilla/editor/libeditor/base/EditAggregateTxn.cpp | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/mozilla/editor/base/EditAggregateTxn.cpp b/mozilla/editor/base/EditAggregateTxn.cpp index f74154668fa..a88877e1af3 100644 --- a/mozilla/editor/base/EditAggregateTxn.cpp +++ b/mozilla/editor/base/EditAggregateTxn.cpp @@ -167,12 +167,19 @@ NS_IMETHODIMP EditAggregateTxn::GetCount(PRInt32 *aCount) NS_IMETHODIMP EditAggregateTxn::GetTxnAt(PRInt32 aIndex, EditTxn **aTxn) { + // preconditions + NS_PRECONDITION(aTxn, "null out param"); + NS_PRECONDITION(mChildren, "bad internal state"); + if (!aTxn) { return NS_ERROR_NULL_POINTER; } + *aTxn = nsnull; // initialize out param as soon as we know it's a valid pointer if (!mChildren) { return NS_ERROR_UNEXPECTED; } + + // get the transaction at aIndex const PRInt32 txnCount = mChildren->Count(); if (0>aIndex || txnCount<=aIndex) { return NS_ERROR_UNEXPECTED; diff --git a/mozilla/editor/libeditor/base/EditAggregateTxn.cpp b/mozilla/editor/libeditor/base/EditAggregateTxn.cpp index f74154668fa..a88877e1af3 100644 --- a/mozilla/editor/libeditor/base/EditAggregateTxn.cpp +++ b/mozilla/editor/libeditor/base/EditAggregateTxn.cpp @@ -167,12 +167,19 @@ NS_IMETHODIMP EditAggregateTxn::GetCount(PRInt32 *aCount) NS_IMETHODIMP EditAggregateTxn::GetTxnAt(PRInt32 aIndex, EditTxn **aTxn) { + // preconditions + NS_PRECONDITION(aTxn, "null out param"); + NS_PRECONDITION(mChildren, "bad internal state"); + if (!aTxn) { return NS_ERROR_NULL_POINTER; } + *aTxn = nsnull; // initialize out param as soon as we know it's a valid pointer if (!mChildren) { return NS_ERROR_UNEXPECTED; } + + // get the transaction at aIndex const PRInt32 txnCount = mChildren->Count(); if (0>aIndex || txnCount<=aIndex) { return NS_ERROR_UNEXPECTED;