From 9d68ddd2ce4bb1625b4a7bc06d85f2b61361d960 Mon Sep 17 00:00:00 2001 From: "scc%mozilla.org" Date: Thu, 31 Aug 2000 06:12:35 +0000 Subject: [PATCH] make |Last| not try to adjust an iterator into an empty string (stops illegal calls to |Last| on an empty string from going into an infinite looop), r=mscott git-svn-id: svn://10.0.0.236/trunk@77752 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/string/public/nsAReadableString.h | 7 ++++++- mozilla/xpcom/ds/nsAReadableString.h | 7 ++++++- mozilla/xpcom/string/public/nsAReadableString.h | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/mozilla/string/public/nsAReadableString.h b/mozilla/string/public/nsAReadableString.h index f0862e8db6a..888574e0d5d 100644 --- a/mozilla/string/public/nsAReadableString.h +++ b/mozilla/string/public/nsAReadableString.h @@ -571,7 +571,12 @@ basic_nsAReadableString::Last() const { NS_ASSERTION(Length()>0, "|Last()| on an empty string"); - return *(EndReading()-=1); + // nsReadingIterator iter; EndReading(iter); + nsReadingIterator iter( EndReading() ); + if ( !IsEmpty() ) + iter -= 1; + + return *iter; // Note: this has undefined results if |IsEmpty()| } template diff --git a/mozilla/xpcom/ds/nsAReadableString.h b/mozilla/xpcom/ds/nsAReadableString.h index f0862e8db6a..888574e0d5d 100644 --- a/mozilla/xpcom/ds/nsAReadableString.h +++ b/mozilla/xpcom/ds/nsAReadableString.h @@ -571,7 +571,12 @@ basic_nsAReadableString::Last() const { NS_ASSERTION(Length()>0, "|Last()| on an empty string"); - return *(EndReading()-=1); + // nsReadingIterator iter; EndReading(iter); + nsReadingIterator iter( EndReading() ); + if ( !IsEmpty() ) + iter -= 1; + + return *iter; // Note: this has undefined results if |IsEmpty()| } template diff --git a/mozilla/xpcom/string/public/nsAReadableString.h b/mozilla/xpcom/string/public/nsAReadableString.h index f0862e8db6a..888574e0d5d 100644 --- a/mozilla/xpcom/string/public/nsAReadableString.h +++ b/mozilla/xpcom/string/public/nsAReadableString.h @@ -571,7 +571,12 @@ basic_nsAReadableString::Last() const { NS_ASSERTION(Length()>0, "|Last()| on an empty string"); - return *(EndReading()-=1); + // nsReadingIterator iter; EndReading(iter); + nsReadingIterator iter( EndReading() ); + if ( !IsEmpty() ) + iter -= 1; + + return *iter; // Note: this has undefined results if |IsEmpty()| } template