Bug 1161932 - Fix coverity warning in nsBidi.cpp. r=smontagu, a=jocheng
authorTed Clancy <tclancy@mozilla.com>
Tue, 12 May 2015 22:49:50 -0400
changeset 238584 bf4e182b1e7523d74c4b786ccb558c9d7d026a73
parent 238583 6a53213b652fc0725e32da2a9481e7aa08d1452d
child 238585 3a54ec1f5ea8fcbede9d8bb69dfcde75aab32890
push id677
push userryanvm@gmail.com
push dateWed, 03 Jun 2015 20:49:30 +0000
treeherdermozilla-b2g37_v2_2@4eea7e9b74da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmontagu, jocheng
bugs1161932
milestone37.0
Bug 1161932 - Fix coverity warning in nsBidi.cpp. r=smontagu, a=jocheng
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;