From: Thomas Geymayer Date: Fri, 7 Jun 2013 16:54:41 +0000 (+0200) Subject: CSSBorder: Do not return unitialized data. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c8af817eebf13f4425692ddd36e5d6919cc91ce4;p=simgear.git CSSBorder: Do not return unitialized data. --- diff --git a/simgear/misc/CSSBorder.cxx b/simgear/misc/CSSBorder.cxx index cf4dd9e7..cc3ffc9a 100644 --- a/simgear/misc/CSSBorder.cxx +++ b/simgear/misc/CSSBorder.cxx @@ -50,26 +50,34 @@ namespace simgear //---------------------------------------------------------------------------- CSSBorder::Offsets CSSBorder::getRelOffsets(const SGRect& 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& 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; } diff --git a/simgear/misc/CSSBorder_test.cxx b/simgear/misc/CSSBorder_test.cxx index 29d43366..5f754504 100644 --- a/simgear/misc/CSSBorder_test.cxx +++ b/simgear/misc/CSSBorder_test.cxx @@ -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(0,0,200,200)); + COMPARE(o.t, 0); + COMPARE(o.r, 0); + COMPARE(o.b, 0); + COMPARE(o.l, 0); + o = b.getRelOffsets(SGRect(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; }