CSSBorder: Do not return unitialized data.

This commit is contained in:
Thomas Geymayer 2013-06-07 18:54:41 +02:00
parent d24d3ce487
commit c8af817eeb
2 changed files with 23 additions and 2 deletions

View File

@ -50,26 +50,34 @@ namespace simgear
//----------------------------------------------------------------------------
CSSBorder::Offsets CSSBorder::getRelOffsets(const SGRect<int>& dim) const
{
Offsets ret;
Offsets ret = {{0}};
if( !valid )
return ret;
for(int i = 0; i < 4; ++i)
{
ret.val[i] = offsets.val[i];
if( !types.rel[i] )
ret.val[i] /= (i & 1) ? dim.height() : dim.width();
}
return ret;
}
//----------------------------------------------------------------------------
CSSBorder::Offsets CSSBorder::getAbsOffsets(const SGRect<int>& dim) const
{
Offsets ret;
Offsets ret = {{0}};
if( !valid )
return ret;
for(int i = 0; i < 4; ++i)
{
ret.val[i] = offsets.val[i];
if( types.rel[i] )
ret.val[i] *= (i & 1) ? dim.height() : dim.width();
}
return ret;
}

View File

@ -86,6 +86,19 @@ int main (int ac, char ** av)
VERIFY(b.getKeyword().empty());
VERIFY(b.isNone());
CSSBorder b2;
VERIFY(!b2.isValid());
o = b.getAbsOffsets(SGRect<int>(0,0,200,200));
COMPARE(o.t, 0);
COMPARE(o.r, 0);
COMPARE(o.b, 0);
COMPARE(o.l, 0);
o = b.getRelOffsets(SGRect<int>(0,0,200,200));
COMPARE(o.t, 0);
COMPARE(o.r, 0);
COMPARE(o.b, 0);
COMPARE(o.l, 0);
std::cout << "all tests passed successfully!" << std::endl;
return 0;
}