bug 166886 r=jesup,stuart sr=tor Crash while loading sourceforge.net (on a debug build) (on Tru64) fixed by doing some code cleanup

This commit is contained in:
cbiesinger%web.de 2002-09-15 19:51:37 +00:00
parent b4bf2436f6
commit 60d1860a11
3 changed files with 51 additions and 45 deletions

View File

@ -75,6 +75,7 @@ nsBMPDecoder::~nsBMPDecoder()
NS_IMETHODIMP nsBMPDecoder::Init(imgILoad *aLoad)
{
mStartDecoding = PR_IntervalNow();
PR_LOG(gBMPLog, PR_LOG_DEBUG, ("nsBMPDecoder::Init(%p)\n", aLoad));
mObserver = do_QueryInterface(aLoad);
@ -118,6 +119,10 @@ NS_IMETHODIMP nsBMPDecoder::Close()
NS_IMETHODIMP nsBMPDecoder::Flush()
{
PRIntervalTime endDec = PR_IntervalNow();
PRUint32 muSec = PR_IntervalToMicroseconds(endDec - mStartDecoding);
PR_LOG(gBMPLog, PR_LOG_DEBUG, ("%lu musec.\n", muSec));
printf("%lu musec\n", muSec);
mFrame->SetMutable(PR_FALSE);
return NS_OK;
}
@ -141,7 +146,7 @@ NS_IMETHODIMP nsBMPDecoder::WriteFrom(nsIInputStream *aInStr, PRUint32 aCount, P
// Actual Data Processing
// ----------------------------------------
inline nsresult nsBMPDecoder::SetPixel(PRUint8*& aDecoded, PRUint8 idx)
nsresult nsBMPDecoder::SetPixel(PRUint8*& aDecoded, PRUint8 idx)
{
PRUint8 red, green, blue;
red = mColors[idx].red;
@ -150,7 +155,7 @@ inline nsresult nsBMPDecoder::SetPixel(PRUint8*& aDecoded, PRUint8 idx)
return SetPixel(aDecoded, red, green, blue);
}
inline nsresult nsBMPDecoder::SetPixel(PRUint8*& aDecoded, PRUint8 aRed, PRUint8 aGreen, PRUint8 aBlue)
nsresult nsBMPDecoder::SetPixel(PRUint8*& aDecoded, PRUint8 aRed, PRUint8 aGreen, PRUint8 aBlue)
{
#if defined(XP_MAC) || defined(XP_MACOSX)
*aDecoded++ = 0; // Mac needs this padding byte
@ -167,7 +172,7 @@ inline nsresult nsBMPDecoder::SetPixel(PRUint8*& aDecoded, PRUint8 aRed, PRUint8
return NS_OK;
}
inline nsresult nsBMPDecoder::Set4BitPixel(PRUint8*& aDecoded, PRUint8 aData, PRUint32& aPos)
nsresult nsBMPDecoder::Set4BitPixel(PRUint8*& aDecoded, PRUint8 aData, PRUint32& aPos)
{
PRUint8 idx = aData >> 4;
nsresult rv = SetPixel(aDecoded, idx);
@ -180,7 +185,7 @@ inline nsresult nsBMPDecoder::Set4BitPixel(PRUint8*& aDecoded, PRUint8 aData, PR
return rv;
}
inline nsresult nsBMPDecoder::SetData(PRUint8* aData)
nsresult nsBMPDecoder::SetData(PRUint8* aData)
{
PRUint32 bpr;
nsresult rv;
@ -461,11 +466,11 @@ NS_METHOD nsBMPDecoder::ProcessData(const char* aBuffer, PRUint32 aCount)
void nsBMPDecoder::ProcessFileHeader()
{
memset(&mBFH, 0, sizeof(mBFH));
DOCOPY(&mBFH.signature, mRawBuf);
DOCOPY(&mBFH.filesize, mRawBuf + 2);
DOCOPY(&mBFH.reserved, mRawBuf + 6);
DOCOPY(&mBFH.dataoffset, mRawBuf + 10);
DOCOPY(&mBFH.bihsize, mRawBuf + 14);
memcpy(&mBFH.signature, mRawBuf, sizeof(mBFH.signature));
memcpy(&mBFH.filesize, mRawBuf + 2, sizeof(mBFH.filesize));
memcpy(&mBFH.reserved, mRawBuf + 6, sizeof(mBFH.reserved));
memcpy(&mBFH.dataoffset, mRawBuf + 10, sizeof(mBFH.dataoffset));
memcpy(&mBFH.bihsize, mRawBuf + 14, sizeof(mBFH.bihsize));
// Now correct the endianness of the header
mBFH.filesize = LITTLE_TO_NATIVE32(mBFH.filesize);
@ -479,20 +484,20 @@ void nsBMPDecoder::ProcessInfoHeader()
if (mBFH.bihsize == 12) { // OS/2 Bitmap
memcpy(&mBIH.width, mRawBuf, 2);
memcpy(&mBIH.height, mRawBuf + 2, 2);
DOCOPY(&mBIH.planes, mRawBuf + 4);
DOCOPY(&mBIH.bpp, mRawBuf + 6);
memcpy(&mBIH.planes, mRawBuf + 4, sizeof(mBIH.planes));
memcpy(&mBIH.bpp, mRawBuf + 6, sizeof(mBIH.bpp));
}
else {
DOCOPY(&mBIH.width, mRawBuf);
DOCOPY(&mBIH.height, mRawBuf + 4);
DOCOPY(&mBIH.planes, mRawBuf + 8);
DOCOPY(&mBIH.bpp, mRawBuf + 10);
DOCOPY(&mBIH.compression, mRawBuf + 12);
DOCOPY(&mBIH.image_size, mRawBuf + 16);
DOCOPY(&mBIH.xppm, mRawBuf + 20);
DOCOPY(&mBIH.yppm, mRawBuf + 24);
DOCOPY(&mBIH.colors, mRawBuf + 28);
DOCOPY(&mBIH.important_colors, mRawBuf + 32);
memcpy(&mBIH.width, mRawBuf, sizeof(mBIH.width));
memcpy(&mBIH.height, mRawBuf + 4, sizeof(mBIH.height));
memcpy(&mBIH.planes, mRawBuf + 8, sizeof(mBIH.planes));
memcpy(&mBIH.bpp, mRawBuf + 10, sizeof(mBIH.bpp));
memcpy(&mBIH.compression, mRawBuf + 12, sizeof(mBIH.compression));
memcpy(&mBIH.image_size, mRawBuf + 16, sizeof(mBIH.image_size));
memcpy(&mBIH.xppm, mRawBuf + 20, sizeof(mBIH.xppm));
memcpy(&mBIH.yppm, mRawBuf + 24, sizeof(mBIH.yppm));
memcpy(&mBIH.colors, mRawBuf + 28, sizeof(mBIH.colors));
memcpy(&mBIH.important_colors, mRawBuf + 32, sizeof(mBIH.important_colors));
}
// Convert endianness

View File

@ -45,6 +45,8 @@
#include "imgIDecoderObserver.h"
#include "gfxIImageFrame.h"
#include <prinrval.h>
#define NS_BMPDECODER_CID \
{ /* {78c61626-4d1f-4843-9364-4652d98ff6e1} */ \
0x78c61626, \
@ -91,8 +93,6 @@ struct bitFields {
PRInt8 blueshift;
};
#define DOCOPY(dest, src) memcpy(dest, src, sizeof(dest))
#if defined WORDS_BIGENDIAN || defined IS_BIG_ENDIAN
#define LITTLE_TO_NATIVE16(x) ((((x) & 0xFF) << 8) | ((x) >> 8))
#define LITTLE_TO_NATIVE32(x) ((((x) & 0xFF) << 24) | \
@ -137,20 +137,20 @@ private:
/** Sets the pixel data in aDecoded to the given values.
* The variable passed in as aDecoded will be moved on 3 bytes! */
inline nsresult SetPixel(PRUint8*& aDecoded, PRUint8 aIdx);
inline nsresult SetPixel(PRUint8*& aDecoded, PRUint8 aRed, PRUint8 aGreen, PRUint8 aBlue);
nsresult SetPixel(PRUint8*& aDecoded, PRUint8 aIdx);
nsresult SetPixel(PRUint8*& aDecoded, PRUint8 aRed, PRUint8 aGreen, PRUint8 aBlue);
/** Sets one or two pixels; it is ensured that aPos is <= mBIH.width
* @param aDecoded where the data is stored. Will be moved 3 or 6 bytes,
* depending on whether one or two pixels are written.
* @param aData The values for the two pixels
* @param aPos Current position. Is incremented by one or two. */
inline nsresult Set4BitPixel(PRUint8*& aDecoded, PRUint8 aData, PRUint32& aPos);
nsresult Set4BitPixel(PRUint8*& aDecoded, PRUint8 aData, PRUint32& aPos);
/** Sets the image data at specified position. mCurLine is used
* to get the row
* @param aData The data */
inline nsresult SetData(PRUint8* aData);
nsresult SetData(PRUint8* aData);
nsCOMPtr<imgIDecoderObserver> mObserver;
@ -176,6 +176,7 @@ private:
void ProcessFileHeader();
void ProcessInfoHeader();
PRIntervalTime mStartDecoding;
};

View File

@ -492,21 +492,21 @@ void
nsICODecoder::ProcessDirEntry(IconDirEntry& aTarget)
{
memset(&aTarget, 0, sizeof(aTarget));
DOCOPY(&aTarget.mWidth, mDirEntryArray);
DOCOPY(&aTarget.mHeight, mDirEntryArray+1);
DOCOPY(&aTarget.mColorCount, mDirEntryArray+2);
DOCOPY(&aTarget.mReserved, mDirEntryArray+3);
memcpy(&aTarget.mWidth, mDirEntryArray, sizeof(aTarget.mWidth));
memcpy(&aTarget.mHeight, mDirEntryArray+1, sizeof(aTarget.mHeight));
memcpy(&aTarget.mColorCount, mDirEntryArray+2, sizeof(aTarget.mColorCount));
memcpy(&aTarget.mReserved, mDirEntryArray+3, sizeof(aTarget.mReserved));
DOCOPY(&aTarget.mPlanes, mDirEntryArray+4);
memcpy(&aTarget.mPlanes, mDirEntryArray+4, sizeof(aTarget.mPlanes));
aTarget.mPlanes = LITTLE_TO_NATIVE16(aTarget.mPlanes);
DOCOPY(&aTarget.mBitCount, mDirEntryArray+6);
memcpy(&aTarget.mBitCount, mDirEntryArray+6, sizeof(aTarget.mBitCount));
aTarget.mBitCount = LITTLE_TO_NATIVE16(aTarget.mBitCount);
DOCOPY(&aTarget.mBytesInRes, mDirEntryArray+8);
memcpy(&aTarget.mBytesInRes, mDirEntryArray+8, sizeof(aTarget.mBytesInRes));
aTarget.mBytesInRes = LITTLE_TO_NATIVE32(aTarget.mBytesInRes);
DOCOPY(&aTarget.mImageOffset, mDirEntryArray+12);
memcpy(&aTarget.mImageOffset, mDirEntryArray+12, sizeof(aTarget.mImageOffset));
aTarget.mImageOffset = LITTLE_TO_NATIVE32(aTarget.mImageOffset);
}
@ -514,16 +514,16 @@ void nsICODecoder::ProcessInfoHeader() {
memset(&mBIH, 0, sizeof(mBIH));
// Ignoring the size; it should always be 40 for icons, anyway
DOCOPY(&mBIH.width, mBIHraw + 4);
DOCOPY(&mBIH.height, mBIHraw + 8);
DOCOPY(&mBIH.planes, mBIHraw + 12);
DOCOPY(&mBIH.bpp, mBIHraw + 14);
DOCOPY(&mBIH.compression, mBIHraw + 16);
DOCOPY(&mBIH.image_size, mBIHraw + 20);
DOCOPY(&mBIH.xppm, mBIHraw + 24);
DOCOPY(&mBIH.yppm, mBIHraw + 28);
DOCOPY(&mBIH.colors, mBIHraw + 32);
DOCOPY(&mBIH.important_colors, mBIHraw + 36);
memcpy(&mBIH.width, mBIHraw + 4, sizeof(mBIH.width));
memcpy(&mBIH.height, mBIHraw + 8, sizeof(mBIH.height));
memcpy(&mBIH.planes, mBIHraw + 12, sizeof(mBIH.planes));
memcpy(&mBIH.bpp, mBIHraw + 14, sizeof(mBIH.bpp));
memcpy(&mBIH.compression, mBIHraw + 16, sizeof(mBIH.compression));
memcpy(&mBIH.image_size, mBIHraw + 20, sizeof(mBIH.image_size));
memcpy(&mBIH.xppm, mBIHraw + 24, sizeof(mBIH.xppm));
memcpy(&mBIH.yppm, mBIHraw + 28, sizeof(mBIH.yppm));
memcpy(&mBIH.colors, mBIHraw + 32, sizeof(mBIH.colors));
memcpy(&mBIH.important_colors, mBIHraw + 36, sizeof(mBIH.important_colors));
// Convert endianness
mBIH.width = LITTLE_TO_NATIVE32(mBIH.width);