Bug 687982 - innocuous uninitialized value fix in nsBMPDecoder. r=joe
authorBrian R. Bondy <netzen@gmail.com>
Wed, 16 Nov 2011 10:14:40 -0500
changeset 80307 d339796e649b5fd62e3e5c6d951d04fdcd6ab12e
parent 80306 913ee424d1d22fd43a3f955d686cf9fceaca8f8c
child 80308 1646f17e51b134ee4a680b3e7ee1b654e94a38b0
push id3400
push userbbondy@mozilla.com
push dateWed, 16 Nov 2011 15:15:35 +0000
treeherdermozilla-inbound@d339796e649b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoe
bugs687982
milestone11.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 687982 - innocuous uninitialized value fix in nsBMPDecoder. r=joe
image/decoders/nsBMPDecoder.cpp
--- a/image/decoders/nsBMPDecoder.cpp
+++ b/image/decoders/nsBMPDecoder.cpp
@@ -374,42 +374,46 @@ nsBMPDecoder::WriteInternal(const char* 
         if ((mBIH.compression == BI_RLE8) || (mBIH.compression == BI_RLE4)) {
             // Clear the image, as the RLE may jump over areas
             memset(mImageData, 0, imageLength);
         }
 
         // Tell the superclass we're starting a frame
         PostFrameStart();
     }
-    PRUint8 bpc; // bytes per color
-    bpc = (mBFH.bihsize == OS2_BIH_LENGTH) ? 3 : 4; // OS/2 Bitmaps have no padding byte
-    if (mColors && (mPos >= mLOH && (mPos < (mLOH + mNumColors * bpc)))) {
-        // We will receive (mNumColors * bpc) bytes of color data
-        PRUint32 colorBytes = mPos - mLOH; // Number of bytes already received
-        PRUint8 colorNum = colorBytes / bpc; // Color which is currently received
-        PRUint8 at = colorBytes % bpc;
-        while (aCount && (mPos < (mLOH + mNumColors * bpc))) {
+
+    if (mColors && mPos >= mLOH) {
+      // OS/2 Bitmaps have no padding byte
+      PRUint8 bytesPerColor = (mBFH.bihsize == OS2_BIH_LENGTH) ? 3 : 4;
+      if (mPos < (mLOH + mNumColors * bytesPerColor)) {
+        // Number of bytes already received
+        PRUint32 colorBytes = mPos - mLOH; 
+        // Color which is currently received
+        PRUint8 colorNum = colorBytes / bytesPerColor;
+        PRUint8 at = colorBytes % bytesPerColor;
+        while (aCount && (mPos < (mLOH + mNumColors * bytesPerColor))) {
             switch (at) {
                 case 0:
                     mColors[colorNum].blue = *aBuffer;
                     break;
                 case 1:
                     mColors[colorNum].green = *aBuffer;
                     break;
                 case 2:
                     mColors[colorNum].red = *aBuffer;
                     colorNum++;
                     break;
                 case 3:
                     // This is a padding byte
                     break;
             }
             mPos++; aBuffer++; aCount--;
-            at = (at + 1) % bpc;
+            at = (at + 1) % bytesPerColor;
         }
+      }
     }
     else if (aCount && mBIH.compression == BI_BITFIELDS && mPos < (WIN_HEADER_LENGTH + BITFIELD_LENGTH)) {
         // If compression is used, this is a windows bitmap, hence we can
         // use WIN_HEADER_LENGTH instead of mLOH
         PRUint32 toCopy = (WIN_HEADER_LENGTH + BITFIELD_LENGTH) - mPos;
         if (toCopy > aCount)
             toCopy = aCount;
         memcpy(mRawBuf + (mPos - WIN_HEADER_LENGTH), aBuffer, toCopy);