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 88422 e0f3f797e0fd03b1613a29c8a4b96112a096a525
parent 88421 7eb6749bbc17a8107fd363bdb905a9f2f8c7c171
child 88423 ab7ed8a7a885178298f104969c35d30967f519c1
push id157
push userMs2ger@gmail.com
push dateWed, 07 Mar 2012 19:27:10 +0000
reviewersjdaggett
bugs732330
milestone13.0a1
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