From c8af817eebf13f4425692ddd36e5d6919cc91ce4 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Fri, 7 Jun 2013 18:54:41 +0200 Subject: [PATCH] CSSBorder: Do not return unitialized data. --- simgear/misc/CSSBorder.cxx | 12 ++++++++++-- simgear/misc/CSSBorder_test.cxx | 13 +++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) 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; } -- 2.39.5