diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-03-28 15:55:31 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-09 20:53:06 +0200 |
commit | e38ad9455099a83e2a8619f19ca949bc64ae6f82 (patch) | |
tree | 5bf265e04708c06df91ac936c818b0a091b86c8e /src/widgets/widgets/qtoolbararealayout.cpp | |
parent | 1a6410f91f5e5edf11508e19176123b54e474e83 (diff) |
Fix crash when trying to place toolbar into zero-height window.
Change QToolBarAreaLayout::item() to return a pointer
and check return values in plug().
Task-number: QTBUG-37183
Change-Id: I7029eb9739cbe603460e87d3e5493f116bdb3a89
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src/widgets/widgets/qtoolbararealayout.cpp')
-rw-r--r-- | src/widgets/widgets/qtoolbararealayout.cpp | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/widgets/widgets/qtoolbararealayout.cpp b/src/widgets/widgets/qtoolbararealayout.cpp index 5ec76569aa..4591c2ac5f 100644 --- a/src/widgets/widgets/qtoolbararealayout.cpp +++ b/src/widgets/widgets/qtoolbararealayout.cpp @@ -1107,16 +1107,19 @@ void QToolBarAreaLayout::clear() rect = QRect(); } -QToolBarAreaLayoutItem &QToolBarAreaLayout::item(const QList<int> &path) +QToolBarAreaLayoutItem *QToolBarAreaLayout::item(const QList<int> &path) { Q_ASSERT(path.count() == 3); - Q_ASSERT(path.at(0) >= 0 && path.at(0) < QInternal::DockCount); + if (path.at(0) < 0 || path.at(0) >= QInternal::DockCount) + return 0; QToolBarAreaLayoutInfo &info = docks[path.at(0)]; - Q_ASSERT(path.at(1) >= 0 && path.at(1) < info.lines.count()); + if (path.at(1) < 0 || path.at(1) >= info.lines.count()) + return 0; QToolBarAreaLayoutLine &line = info.lines[path.at(1)]; - Q_ASSERT(path.at(2) >= 0 && path.at(2) < line.toolBarItems.count()); - return line.toolBarItems[path.at(2)]; + if (path.at(2) < 0 || path.at(2) >= line.toolBarItems.count()) + return 0; + return &(line.toolBarItems[path.at(2)]); } QRect QToolBarAreaLayout::itemRect(const QList<int> &path) const @@ -1132,23 +1135,28 @@ QRect QToolBarAreaLayout::itemRect(const QList<int> &path) const QLayoutItem *QToolBarAreaLayout::plug(const QList<int> &path) { - QToolBarAreaLayoutItem &item = this->item(path); - Q_ASSERT(item.gap); - Q_ASSERT(item.widgetItem != 0); - item.gap = false; - return item.widgetItem; + QToolBarAreaLayoutItem *item = this->item(path); + if (!item) { + qWarning() << Q_FUNC_INFO << "No item at" << path; + return 0; + } + Q_ASSERT(item->gap); + Q_ASSERT(item->widgetItem != 0); + item->gap = false; + return item->widgetItem; } QLayoutItem *QToolBarAreaLayout::unplug(const QList<int> &path, QToolBarAreaLayout *other) { //other needs to be update as well Q_ASSERT(path.count() == 3); - QToolBarAreaLayoutItem &item = this->item(path); + QToolBarAreaLayoutItem *item = this->item(path); + Q_ASSERT(item); //update the leading space here QToolBarAreaLayoutInfo &info = docks[path.at(0)]; QToolBarAreaLayoutLine &line = info.lines[path.at(1)]; - if (item.size != pick(line.o, item.realSizeHint())) { + if (item->size != pick(line.o, item->realSizeHint())) { //the item doesn't have its default size //so we'll give this to the next item int newExtraSpace = 0; @@ -1185,9 +1193,9 @@ QLayoutItem *QToolBarAreaLayout::unplug(const QList<int> &path, QToolBarAreaLayo } } - Q_ASSERT(!item.gap); - item.gap = true; - return item.widgetItem; + Q_ASSERT(!item->gap); + item->gap = true; + return item->widgetItem; } static QRect unpackRect(uint geom0, uint geom1, bool *floating) |