Bug 1081858 - Part 1. Fix aText off-by-one indexing. r=jfkthame
authorKan-Ru Chen <kanru@kanru.info>
Mon, 24 Oct 2016 22:00:03 +0800
changeset 362543 8d6560b363d27d62db58d16173e84264537c29e2
parent 362542 e48bc2dc52895542e7988b0eafdda2535f68e639
child 362544 766b5a6cec7c6724611453258e13a040dcdcaf4a
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-beta@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1081858
milestone52.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 1081858 - Part 1. Fix aText off-by-one indexing. r=jfkthame MozReview-Commit-ID: 6LAlEntU6C7
layout/generic/nsTextFrameUtils.cpp
--- a/layout/generic/nsTextFrameUtils.cpp
+++ b/layout/generic/nsTextFrameUtils.cpp
@@ -46,17 +46,17 @@ nsTextFrameUtils::TransformText(const ch
 
   bool lastCharArabic = false;
 
   if (aCompression == COMPRESS_NONE ||
       aCompression == COMPRESS_NONE_TRANSFORM_TO_SPACE) {
     // Skip discardables.
     uint32_t i;
     for (i = 0; i < aLength; ++i) {
-      char16_t ch = *aText++;
+      char16_t ch = aText[i];
       if (IsDiscardable(ch, &flags)) {
         aSkipChars->SkipChar();
       } else {
         aSkipChars->KeepChar();
         if (ch > ' ') {
           lastCharArabic = IS_ARABIC_CHAR(ch);
         } else if (aCompression == COMPRESS_NONE_TRANSFORM_TO_SPACE) {
           if (ch == '\t' || ch == '\n') {
@@ -77,25 +77,25 @@ nsTextFrameUtils::TransformText(const ch
     } else {
       *aIncomingFlags &= ~INCOMING_ARABICCHAR;
     }
     *aIncomingFlags &= ~INCOMING_WHITESPACE;
   } else {
     bool inWhitespace = (*aIncomingFlags & INCOMING_WHITESPACE) != 0;
     uint32_t i;
     for (i = 0; i < aLength; ++i) {
-      char16_t ch = *aText++;
+      char16_t ch = aText[i];
       bool nowInWhitespace;
       if (ch == ' ' &&
           (i + 1 >= aLength ||
-           !IsSpaceCombiningSequenceTail(aText, aLength - (i + 1)))) {
+           !IsSpaceCombiningSequenceTail(&aText[i + 1], aLength - (i + 1)))) {
         nowInWhitespace = true;
       } else if (ch == '\n' && aCompression == COMPRESS_WHITESPACE_NEWLINE) {
-        if (i > 0 && IS_CJ_CHAR(aText[-1]) &&
-            i + 1 < aLength && IS_CJ_CHAR(aText[1])) {
+        if (i > 0 && IS_CJ_CHAR(aText[i - 1]) &&
+            i + 1 < aLength && IS_CJ_CHAR(aText[i + 1])) {
           // Discard newlines between CJK chars.
           // XXX this really requires more context to get right!
           aSkipChars->SkipChar();
           continue;
         }
         nowInWhitespace = true;
       } else {
         nowInWhitespace = ch == '\t';
@@ -153,17 +153,17 @@ nsTextFrameUtils::TransformText(const ui
   uint32_t flags = 0;
   uint8_t* outputStart = aOutput;
 
   if (aCompression == COMPRESS_NONE ||
       aCompression == COMPRESS_NONE_TRANSFORM_TO_SPACE) {
     // Skip discardables.
     uint32_t i;
     for (i = 0; i < aLength; ++i) {
-      uint8_t ch = *aText++;
+      uint8_t ch = aText[i];
       if (IsDiscardable(ch, &flags)) {
         aSkipChars->SkipChar();
       } else {
         aSkipChars->KeepChar();
         if (aCompression == COMPRESS_NONE_TRANSFORM_TO_SPACE) {
           if (ch == '\t' || ch == '\n') {
             ch = ' ';
             flags |= TEXT_WAS_TRANSFORMED;
@@ -177,17 +177,17 @@ nsTextFrameUtils::TransformText(const ui
         *aOutput++ = ch;
       }
     }
     *aIncomingFlags &= ~(INCOMING_ARABICCHAR | INCOMING_WHITESPACE);
   } else {
     bool inWhitespace = (*aIncomingFlags & INCOMING_WHITESPACE) != 0;
     uint32_t i;
     for (i = 0; i < aLength; ++i) {
-      uint8_t ch = *aText++;
+      uint8_t ch = aText[i];
       bool nowInWhitespace = ch == ' ' || ch == '\t' ||
         (ch == '\n' && aCompression == COMPRESS_WHITESPACE_NEWLINE);
       if (!nowInWhitespace) {
         if (IsDiscardable(ch, &flags)) {
           aSkipChars->SkipChar();
           nowInWhitespace = inWhitespace;
         } else {
           *aOutput++ = ch;