bug 732330 - add assertion in ClusterIterator::Next to check for sane/safe result. r=jdaggett
authorJonathan Kew <jfkthame@gmail.com>
Sun, 04 Mar 2012 08:58:54 +0000
changeset 88223 e0f3f797e0fd03b1613a29c8a4b96112a096a525
parent 88222 7eb6749bbc17a8107fd363bdb905a9f2f8c7c171
child 88224 ab7ed8a7a885178298f104969c35d30967f519c1
push id22179
push userbmo@edmorley.co.uk
push dateSun, 04 Mar 2012 22:43:30 +0000
treeherdermozilla-central@433cfbd2a0da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdaggett
bugs732330
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 732330 - add assertion in ClusterIterator::Next to check for sane/safe result. r=jdaggett
intl/unicharutil/public/nsUnicodeProperties.h
intl/unicharutil/src/nsUnicodeProperties.cpp
--- a/intl/unicharutil/public/nsUnicodeProperties.h
+++ b/intl/unicharutil/public/nsUnicodeProperties.h
@@ -95,32 +95,37 @@ enum ShapingType {
 PRInt32 ScriptShapingType(PRInt32 aScriptCode);
 
 // A simple iterator for a string of PRUnichar codepoints that advances
 // by Unicode grapheme clusters
 class ClusterIterator
 {
 public:
     ClusterIterator(const PRUnichar* aText, PRUint32 aLength)
-        : mText(aText), mLimit(aText + aLength), mPos(aText)
+        : mPos(aText), mLimit(aText + aLength)
+#ifdef DEBUG
+        , mText(aText)
+#endif
     { }
 
     operator const PRUnichar* () const {
         return mPos;
     }
 
     bool AtEnd() const {
         return mPos >= mLimit;
     }
 
     void Next();
 
 private:
-    const PRUnichar* mText;
+    const PRUnichar* mPos;
     const PRUnichar* mLimit;
-    const PRUnichar* mPos;
+#ifdef DEBUG
+    const PRUnichar* mText;
+#endif
 };
 
 } // end namespace unicode
 
 } // end namespace mozilla
 
 #endif /* NS_UNICODEPROPERTIES_H */
--- a/intl/unicharutil/src/nsUnicodeProperties.cpp
+++ b/intl/unicharutil/src/nsUnicodeProperties.cpp
@@ -349,13 +349,16 @@ ClusterIterator::Next()
             break;
         }
 
         mPos++;
         if (!IS_IN_BMP(ch)) {
             mPos++;
         }
     }
+
+    NS_ASSERTION(mText < mPos && mPos <= mLimit,
+                 "ClusterIterator::Next has overshot the string!");
 }
 
 } // end namespace unicode
 
 } // end namespace mozilla