Bug 1275064 - Use unsigned type in RealWord bitfield. r=froydnj
authorEric Rahm <erahm@mozilla.com>
Wed, 25 May 2016 12:15:27 -0700
changeset 338057 0928a16792af6f0a947b1fdca5b12d16b84eaca0
parent 338056 cf2422741caa849af5dd681d7a976604d0d7dfa3
child 338058 661db976e5e8685e129efa82df0ce21bb5eaed15
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1275064
milestone49.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 1275064 - Use unsigned type in RealWord bitfield. r=froydnj
extensions/spellcheck/src/mozInlineSpellWordUtil.cpp
extensions/spellcheck/src/mozInlineSpellWordUtil.h
--- a/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp
+++ b/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp
@@ -778,17 +778,17 @@ mozInlineSpellWordUtil::FindRealWordCont
       return index - 1;
   }
 
   // We allow ourselves to return the end of this word even if we're
   // doing HINT_START. This will only happen if there is no word which this
   // point is the start of. I'm not 100% sure this is OK...
   const RealWord& word = mRealWords[index];
   int32_t offset = aSoftTextOffset - word.mSoftTextOffset;
-  if (offset >= 0 && offset <= word.mLength)
+  if (offset >= 0 && offset <= static_cast<int32_t>(word.mLength))
     return index;
 
   if (aSearchForward) {
     if (mRealWords[0].mSoftTextOffset > aSoftTextOffset) {
       // All words have mSoftTextOffset > aSoftTextOffset
       return 0;
     }
     // 'index' is the last word such that mSoftTextOffset <= aSoftTextOffset.
--- a/extensions/spellcheck/src/mozInlineSpellWordUtil.h
+++ b/extensions/spellcheck/src/mozInlineSpellWordUtil.h
@@ -120,23 +120,24 @@ private:
       : mNodeOffset(aNodeOffset), mSoftTextOffset(aSoftTextOffset),
         mLength(aLength) {}
   };
   nsTArray<DOMTextMapping> mSoftTextDOMMapping;
   
   // A list of the "real words" in mSoftText, ordered by mSoftTextOffset
   struct RealWord {
     int32_t      mSoftTextOffset;
-    int32_t      mLength : 31;
-    int32_t mCheckableWord : 1;
+    uint32_t      mLength : 31;
+    uint32_t mCheckableWord : 1;
     
-    RealWord(int32_t aOffset, int32_t aLength, bool aCheckable)
+    RealWord(int32_t aOffset, uint32_t aLength, bool aCheckable)
       : mSoftTextOffset(aOffset), mLength(aLength), mCheckableWord(aCheckable)
     {
       static_assert(sizeof(RealWord) == 8, "RealWord should be limited to 8 bytes");
+      MOZ_ASSERT(aLength < INT32_MAX, "Word length is too large to fit in the bitfield");
     }
 
     int32_t EndOffset() const { return mSoftTextOffset + mLength; }
   };
   nsTArray<RealWord> mRealWords;
   int32_t            mNextWordIndex;
 
   bool mSoftTextValid;