Bug 1161932 - Fix coverity warning in nsBidi.cpp. r=smontagu
authorTed Clancy <tclancy@mozilla.com>
Tue, 12 May 2015 22:49:50 -0400
changeset 243657 10eeb41f267465dd85b96d293e4f6ddc025c24aa
parent 243656 99a943203f6e78fcb37838d4eb4d93ff81e9c2b4
child 243658 90e184f46b30a2e6123d797b911270157aa8b95d
push id28744
push userkwierso@gmail.com
push dateWed, 13 May 2015 18:12:16 +0000
treeherdermozilla-central@324c3423deaf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmontagu
bugs1161932
milestone41.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 1161932 - Fix coverity warning in nsBidi.cpp. r=smontagu
layout/base/nsBidi.cpp
--- a/layout/base/nsBidi.cpp
+++ b/layout/base/nsBidi.cpp
@@ -664,17 +664,17 @@ void nsBidi::ResolveExplicitLevels(nsBid
 
     /* (X1) level is set for all codes, embeddingLevel keeps track of the push/pop operations */
     /* both variables may carry the NSBIDI_LEVEL_OVERRIDE flag to indicate the override status */
     nsBidiLevel embeddingLevel = level, newLevel;
     nsBidiLevel previousLevel = level;     /* previous level for regular (not CC) characters */
 
     uint16_t stack[NSBIDI_MAX_EXPLICIT_LEVEL + 2];   /* we never push anything >=NSBIDI_MAX_EXPLICIT_LEVEL
                                                         but we need one more entry as base */
-    uint32_t stackLast = 0;
+    int32_t stackLast = 0;
     int32_t overflowIsolateCount = 0;
     int32_t overflowEmbeddingCount = 0;
     int32_t validIsolateCount = 0;
 
     stack[0] = level;
 
     /* recalculate the flags */
     flags=0;
@@ -768,18 +768,24 @@ void nsBidi::ResolveExplicitLevels(nsBid
             dirProps[i] |= IGNORE_CC;
             overflowIsolateCount--;
           } else if (validIsolateCount) {
             overflowEmbeddingCount = 0;
             while (stack[stackLast] < ISOLATE) {
               /* pop embedding entries        */
               /* until the last isolate entry */
               stackLast--;
+
+              // Since validIsolateCount is true, there must be an isolate entry
+              // on the stack, so the stack is guaranteed to not be empty.
+              // Still, to eliminate a warning from coverity, we use an assertion.
+              MOZ_ASSERT(stackLast > 0);
             }
             stackLast--;  /* pop also the last isolate entry */
+            MOZ_ASSERT(stackLast >= 0);  // For coverity
             validIsolateCount--;
           } else {
             dirProps[i] |= IGNORE_CC;
           }
           embeddingLevel = stack[stackLast] & ~ISOLATE;
           previousLevel = level = embeddingLevel;
           flags |= DIRPROP_FLAG(O_N) | DIRPROP_FLAG(BN) | DIRPROP_FLAG_LR(embeddingLevel);
           break;