From feb01ac8f7dfdf4387433c6606c497afe22863e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Wang?= Date: Fri, 25 Mar 2011 16:38:59 +1300 Subject: [PATCH] b=605605 Uninitialised value used in nsMathMLChar r=karlt --HG-- extra : transplant_source : _G%B6%C6%C6q%C0a%F0f-%CD%AF%FB%FE%F0%BAYc%D5 --- layout/mathml/nsMathMLChar.cpp | 43 ++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/layout/mathml/nsMathMLChar.cpp b/layout/mathml/nsMathMLChar.cpp index 59a74b95238..bd1478261b3 100644 --- a/layout/mathml/nsMathMLChar.cpp +++ b/layout/mathml/nsMathMLChar.cpp @@ -1156,7 +1156,8 @@ public: nscoord aTargetSize, PRUint32 aStretchHint, nsBoundingMetrics& aStretchedMetrics, - const nsAString& aFamilies) + const nsAString& aFamilies, + PRBool& aGlyphFound) : mChar(aChar), mPresContext(aPresContext), mRenderingContext(aRenderingContext), @@ -1166,7 +1167,8 @@ public: mBoundingMetrics(aStretchedMetrics), mFamilies(aFamilies), mTryVariants(PR_TRUE), - mTryParts(PR_TRUE) {} + mTryParts(PR_TRUE), + mGlyphFound(aGlyphFound) {} static PRBool EnumCallback(const nsString& aFamily, PRBool aGeneric, void *aData); @@ -1195,6 +1197,7 @@ public: private: nsAutoTArray mTablesTried; nsGlyphTable* mGlyphTable; // for this callback + PRBool& mGlyphFound; }; @@ -1250,6 +1253,7 @@ nsMathMLChar::StretchEnumContext::TryVariants(nsGlyphTable* aGlyphTable, if (largeopOnly || IsSizeBetter(charSize, bestSize, mTargetSize, mStretchHint)) { + mGlyphFound = PR_TRUE; if (maxWidth) { // IsSizeBetter() checked that charSize < maxsize; // Leave ascent, descent, and bestsize as these contain maxsize. @@ -1320,6 +1324,7 @@ nsMathMLChar::StretchEnumContext::TryParts(nsGlyphTable* aGlyphTable, // all went well, painting will be delegated from now on to children mChar->mGlyph = kNullGlyph; // this will tell paint to build by parts + mGlyphFound = PR_TRUE; mChar->mGlyphTable = aGlyphTable; mBoundingMetrics = compositeSize; return PR_TRUE; // no more searching @@ -1447,6 +1452,7 @@ nsMathMLChar::StretchEnumContext::TryParts(nsGlyphTable* aGlyphTable, mBoundingMetrics.leftBearing = 0; mBoundingMetrics.rightBearing = computedSize; } + mGlyphFound = PR_TRUE; if (maxWidth) return PR_FALSE; // Continue to check other sizes @@ -1565,7 +1571,6 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext, } if (!maxWidth) { - mScaleY = mScaleX = 1.0; mUnscaledAscent = aDesiredStretchSize.ascent; } @@ -1655,6 +1660,7 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext, // 2/3. Search for a glyph or set of part glyphs of appropriate size //////////////////////////////////////////////////////////////////////////////////// + PRBool glyphFound = PR_FALSE; nsAutoString cssFamilies; if (!done) { @@ -1669,7 +1675,7 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext, StretchEnumContext enumData(this, aPresContext, aRenderingContext, aStretchDirection, targetSize, aStretchHint, - aDesiredStretchSize, font.name); + aDesiredStretchSize, font.name, glyphFound); enumData.mTryParts = PR_FALSE; done = !font.EnumerateFamilies(StretchEnumContext::EnumCallback, &enumData); @@ -1683,7 +1689,7 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext, StretchEnumContext enumData(this, aPresContext, aRenderingContext, aStretchDirection, targetSize, aStretchHint, - aDesiredStretchSize, font.name); + aDesiredStretchSize, font.name, glyphFound); enumData.mTryVariants = PR_FALSE; done = !font.EnumerateFamilies(StretchEnumContext::EnumCallback, &enumData); @@ -1704,7 +1710,7 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext, #endif StretchEnumContext enumData(this, aPresContext, aRenderingContext, aStretchDirection, targetSize, aStretchHint, - aDesiredStretchSize, font.name); + aDesiredStretchSize, font.name, glyphFound); enumData.mTryParts = !largeopOnly; font.EnumerateFamilies(StretchEnumContext::EnumCallback, &enumData); @@ -1713,7 +1719,7 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext, if (!maxWidth) { // Now, we know how we are going to draw the char. Update the member // variables accordingly. - mDrawNormal = (mGlyph.font == -1); + mDrawNormal = !glyphFound; mUnscaledAscent = aDesiredStretchSize.ascent; } @@ -1725,7 +1731,9 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext, (aDesiredStretchSize.ascent + aDesiredStretchSize.descent); if (!largeop || scale > 1.0) { // make the character match the desired height. - mScaleY *= scale; + if (!maxWidth) { + mScaleY *= scale; + } aDesiredStretchSize.ascent *= scale; aDesiredStretchSize.descent *= scale; } @@ -1735,7 +1743,9 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext, (aDesiredStretchSize.rightBearing - aDesiredStretchSize.leftBearing); if (!largeop || scale > 1.0) { // make the character match the desired width. - mScaleX *= scale; + if (!maxWidth) { + mScaleX *= scale; + } aDesiredStretchSize.leftBearing *= scale; aDesiredStretchSize.rightBearing *= scale; aDesiredStretchSize.width *= scale; @@ -1745,7 +1755,7 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext, // We do not have a char variant for this largeop in display mode, so we // apply a scale transform to the base char. - if (mGlyph.font == -1 && largeop) { + if (!glyphFound && largeop) { float scale; float largeopFactor = M_SQRT2; @@ -1756,7 +1766,9 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext, scale = (largeopFactor * (initialSize.rightBearing - initialSize.leftBearing)) / (aDesiredStretchSize.rightBearing - aDesiredStretchSize.leftBearing); - mScaleX *= scale; + if (!maxWidth) { + mScaleX *= scale; + } aDesiredStretchSize.leftBearing *= scale; aDesiredStretchSize.rightBearing *= scale; aDesiredStretchSize.width *= scale; @@ -1773,7 +1785,9 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext, scale = (largeopFactor * (initialSize.ascent + initialSize.descent)) / (aDesiredStretchSize.ascent + aDesiredStretchSize.descent); - mScaleY *= scale; + if (!maxWidth) { + mScaleY *= scale; + } aDesiredStretchSize.ascent *= scale; aDesiredStretchSize.descent *= scale; } @@ -1795,9 +1809,8 @@ nsMathMLChar::Stretch(nsPresContext* aPresContext, NS_STRETCH_INTEGRAL)), "Unexpected stretch flags"); - // This will be updated if a better match than the base character is found - mGlyph.font = -1; - + mDrawNormal = PR_TRUE; + mScaleY = mScaleX = 1.0; mDirection = aStretchDirection; nsresult rv = StretchInternal(aPresContext, aRenderingContext, mDirection,