Bug 472593. Don't call line-breaker's Next() method when already at end of text. r=bz,sr=roc
authorJonathan Kew <jfkthame@gmail.com>
Mon, 19 Jan 2009 22:07:11 +1300
changeset 23927 3afab626d3aa642de031373b619da34de555ec20
parent 23926 fb2d014e035264beec44c6aa18b1e83661d9b1de
child 23928 aeec7f7f4476b126ff2d4c1467ac7c593d97eb38
push id4800
push userrocallahan@mozilla.com
push dateMon, 19 Jan 2009 09:37:39 +0000
treeherdermozilla-central@afec2ee5b993 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, roc
bugs472593
milestone1.9.2a1pre
Bug 472593. Don't call line-breaker's Next() method when already at end of text. r=bz,sr=roc
content/base/src/nsPlainTextSerializer.cpp
intl/lwbrk/src/nsJISx4501LineBreaker.cpp
--- a/content/base/src/nsPlainTextSerializer.cpp
+++ b/content/base/src/nsPlainTextSerializer.cpp
@@ -1381,18 +1381,19 @@ nsPlainTextSerializer::AddToLine(const P
       }
       
       nsAutoString restOfLine;
       if (goodSpace == NS_LINEBREAKER_NEED_MORE_TEXT) {
         // If we don't found a good place to break, accept long line and
         // try to find another place to break
         goodSpace=(prefixwidth>mWrapColumn+1)?1:mWrapColumn-prefixwidth+1;
         if (mLineBreaker) {
-          goodSpace = mLineBreaker->Next(mCurrentLine.get(), 
-                                      mCurrentLine.Length(), goodSpace);
+          if (goodSpace < mCurrentLine.Length())
+            goodSpace = mLineBreaker->Next(mCurrentLine.get(), 
+                                           mCurrentLine.Length(), goodSpace);
           if (goodSpace == NS_LINEBREAKER_NEED_MORE_TEXT)
             goodSpace = mCurrentLine.Length();
         }
         // fallback if the line breaker is unavailable or failed
         if (!mLineBreaker) {
           goodSpace=(prefixwidth>mWrapColumn)?1:mWrapColumn-prefixwidth;
           while (goodSpace < linelength &&
                  !nsCRT::IsAsciiSpace(mCurrentLine.CharAt(goodSpace))) {
--- a/intl/lwbrk/src/nsJISx4501LineBreaker.cpp
+++ b/intl/lwbrk/src/nsJISx4501LineBreaker.cpp
@@ -781,28 +781,29 @@ nsJISx4051LineBreaker::WordMove(const PR
   return ret;
 }
 
 PRInt32
 nsJISx4051LineBreaker::Next(const PRUnichar* aText, PRUint32 aLen,
                             PRUint32 aPos) 
 {
   NS_ASSERTION(aText, "aText shouldn't be null");
-  NS_ASSERTION(aLen > aPos, "Illegal value (length > position)");
+  NS_ASSERTION(aLen > aPos, "Bad position passed to nsJISx4051LineBreaker::Next");
 
   PRInt32 nextPos = WordMove(aText, aLen, aPos, 1);
   return nextPos < PRInt32(aLen) ? nextPos : NS_LINEBREAKER_NEED_MORE_TEXT;
 }
 
 PRInt32
 nsJISx4051LineBreaker::Prev(const PRUnichar* aText, PRUint32 aLen,
                             PRUint32 aPos) 
 {
   NS_ASSERTION(aText, "aText shouldn't be null");
-  NS_ASSERTION(aLen >= aPos, "Illegal value (length >= position)");
+  NS_ASSERTION(aLen >= aPos && aPos > 0,
+               "Bad position passed to nsJISx4051LineBreaker::Prev");
 
   PRInt32 prevPos = WordMove(aText, aLen, aPos, -1);
   return prevPos > 0 ? prevPos : NS_LINEBREAKER_NEED_MORE_TEXT;
 }
 
 void
 nsJISx4051LineBreaker::GetJISx4051Breaks(const PRUnichar* aChars, PRUint32 aLength,
                                          PRPackedBool* aBreakBefore)