diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-11-14 23:19:49 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-11-14 23:19:49 +0300 |
commit | b91146d2cee7397ea952cf7870e04df316d9613e (patch) | |
tree | 3101318c8314bf3f2c88da67f62d1c182bc27ddc /src/gui/widgets | |
parent | bcf7e61d6dd87164d79a211cbda1378e1ddc77bd (diff) | |
download | mv-b91146d2cee7397ea952cf7870e04df316d9613e.tar.gz mv-b91146d2cee7397ea952cf7870e04df316d9613e.tar.bz2 mv-b91146d2cee7397ea952cf7870e04df316d9613e.tar.xz mv-b91146d2cee7397ea952cf7870e04df316d9613e.zip |
Fix incorrect memory access if hiding some gui layout cells.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/layout.cpp | 19 | ||||
-rw-r--r-- | src/gui/widgets/layout.h | 4 |
2 files changed, 15 insertions, 8 deletions
diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index 7f2f1f621..f0359062e 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -222,11 +222,15 @@ LayoutCell &LayoutArray::place(gcn::Widget *widget, int x, int y, int w, int h) return cell; } -void LayoutArray::align(int &pos, int &size, int dim, - LayoutCell const &cell, int *sizes) const +void LayoutArray::align(int &pos, int &size, int dim, LayoutCell const &cell, + int *sizes, int sizeCount) const { int size_max = sizes[0]; - for (int i = 1; i < cell.mExtent[dim]; ++i) + int cnt = cell.mExtent[dim]; + if (sizeCount && cell.mExtent[dim] > sizeCount) + cnt = sizeCount; + + for (int i = 1; i < cnt; ++i) size_max += sizes[i] + mSpacing; size = std::min<int>(cell.mSize[dim], size_max); @@ -274,7 +278,8 @@ std::vector<int> LayoutArray::getSizes(int dim, int upp) const } } - if (upp == Layout::AUTO_DEF) return sizes; + if (upp == Layout::AUTO_DEF) + return sizes; // Compute the FILL sizes. int nb = static_cast<int>(sizes.size()); @@ -343,8 +348,10 @@ void LayoutArray::reflow(int nx, int ny, int nw, int nh) if (cell && cell->mType != LayoutCell::NONE) { int dx = x, dy = y, dw = 0, dh = 0; - align(dx, dw, 0, *cell, &widths[gridX]); - align(dy, dh, 1, *cell, &heights[gridY]); + align(dx, dw, 0, *cell, &widths[gridX], + widths.size() - gridX); + align(dy, dh, 1, *cell, &heights[gridY], + heights.size() - gridY); cell->reflow(dx, dy, dw, dh); } x += widths[gridX] + mSpacing; diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h index c4c703644..754d13a0b 100644 --- a/src/gui/widgets/layout.h +++ b/src/gui/widgets/layout.h @@ -127,8 +127,8 @@ class LayoutArray /** * Gets the position and size of a widget along a given axis */ - void align(int &pos, int &size, int dim, - LayoutCell const &cell, int *sizes) const; + void align(int &pos, int &size, int dim, LayoutCell const &cell, + int *sizes, int sizeCount) const; /** * Ensures the private vectors are large enough. |