Don't do floating point assignment from uninitialized data, since it can crash. b=422011 r+sr=bzbarsky a=damon

This commit is contained in:
dbaron@dbaron.org 2008-03-12 15:05:27 -07:00
Родитель f7a428516e
Коммит 30594074ab
2 изменённых файлов: 14 добавлений и 8 удалений

Просмотреть файл

@ -127,30 +127,36 @@ nsCSSValue::nsCSSValue(nsCSSValue::Image* aValue)
nsCSSValue::nsCSSValue(const nsCSSValue& aCopy)
: mUnit(aCopy.mUnit)
{
if ((eCSSUnit_String <= mUnit) && (mUnit <= eCSSUnit_Attr)) {
if (mUnit <= eCSSUnit_Dummy) {
// nothing to do, but put this important case first
}
else if (eCSSUnit_Percent <= mUnit) {
mValue.mFloat = aCopy.mValue.mFloat;
}
else if (eCSSUnit_String <= mUnit && mUnit <= eCSSUnit_Attr) {
mValue.mString = aCopy.mValue.mString;
mValue.mString->AddRef();
}
else if ((eCSSUnit_Integer <= mUnit) && (mUnit <= eCSSUnit_EnumColor)) {
else if (eCSSUnit_Integer <= mUnit && mUnit <= eCSSUnit_EnumColor) {
mValue.mInt = aCopy.mValue.mInt;
}
else if (eCSSUnit_Color == mUnit){
else if (eCSSUnit_Color == mUnit) {
mValue.mColor = aCopy.mValue.mColor;
}
else if (eCSSUnit_Array <= mUnit && mUnit <= eCSSUnit_Counters) {
mValue.mArray = aCopy.mValue.mArray;
mValue.mArray->AddRef();
}
else if (eCSSUnit_URL == mUnit){
else if (eCSSUnit_URL == mUnit) {
mValue.mURL = aCopy.mValue.mURL;
mValue.mURL->AddRef();
}
else if (eCSSUnit_Image == mUnit){
else if (eCSSUnit_Image == mUnit) {
mValue.mImage = aCopy.mValue.mImage;
mValue.mImage->AddRef();
}
else {
mValue.mFloat = aCopy.mValue.mFloat;
NS_NOTREACHED("unknown unit");
}
}
@ -166,7 +172,7 @@ nsCSSValue& nsCSSValue::operator=(const nsCSSValue& aCopy)
PRBool nsCSSValue::operator==(const nsCSSValue& aOther) const
{
if (mUnit == aOther.mUnit) {
if (mUnit <= eCSSUnit_System_Font) {
if (mUnit <= eCSSUnit_Dummy) {
return PR_TRUE;
}
else if ((eCSSUnit_String <= mUnit) && (mUnit <= eCSSUnit_Attr)) {

Просмотреть файл

@ -138,7 +138,7 @@ public:
explicit nsCSSValue(nsCSSUnit aUnit = eCSSUnit_Null)
: mUnit(aUnit)
{
NS_ASSERTION(aUnit <= eCSSUnit_System_Font, "not a valueless unit");
NS_ASSERTION(aUnit <= eCSSUnit_Dummy, "not a valueless unit");
}
nsCSSValue(PRInt32 aValue, nsCSSUnit aUnit) NS_HIDDEN;