mirror of https://github.com/axmolengine/axmol.git
Avoid of type overflow while list size calculation. (#17697)
If _items container is empty `(length - 1) * _itemsMargin` will be large positive value. Using `size_t` causes type overflow and large positive sizes. Using int will cause negative size values. Direct check looks like the best way.
This commit is contained in:
parent
8df9f1eb7a
commit
9f15e34257
|
@ -117,7 +117,7 @@ void ListView::updateInnerContainerSize()
|
|||
case Direction::VERTICAL:
|
||||
{
|
||||
size_t length = _items.size();
|
||||
float totalHeight = (length - 1) * _itemsMargin + (_topPadding + _bottomPadding);
|
||||
float totalHeight = (length == 0) ? 0.0f : (length - 1) * _itemsMargin + (_topPadding + _bottomPadding);
|
||||
for (auto& item : _items)
|
||||
{
|
||||
totalHeight += item->getContentSize().height;
|
||||
|
@ -130,7 +130,7 @@ void ListView::updateInnerContainerSize()
|
|||
case Direction::HORIZONTAL:
|
||||
{
|
||||
size_t length = _items.size();
|
||||
float totalWidth = (length - 1) * _itemsMargin + (_leftPadding + _rightPadding);
|
||||
float totalWidth = (length == 0) ? 0.0f : (length - 1) * _itemsMargin + (_leftPadding + _rightPadding);
|
||||
for (auto& item : _items)
|
||||
{
|
||||
totalWidth += item->getContentSize().width;
|
||||
|
|
Loading…
Reference in New Issue