Debugger: Avoid potential nullptr access

Item may be a nullptr, so do not access it.

Change-Id: I3fdbe30dbbd451027c23c9ed06f08396f0ce215a
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Tobias Hunger
2020-01-20 09:45:26 +01:00
parent 8f130039e3
commit 5995569063

View File

@@ -1693,25 +1693,19 @@ bool WatchModel::contextMenuEvent(const ItemViewEvent &ev)
menu->addMenu(createBreakpointMenu(item, menu)); menu->addMenu(createBreakpointMenu(item, menu));
menu->addSeparator(); menu->addSeparator();
addAction(menu, tr("Expand All Children"), addAction(menu, tr("Expand All Children"), item, [this, name = item ? item->iname : QString()] {
item,
[this, name = item->iname] {
m_expandedINames.insert(name); m_expandedINames.insert(name);
if (auto item = findItem(name)) { if (auto item = findItem(name)) {
item->forFirstLevelChildren([this](WatchItem *child) { item->forFirstLevelChildren(
m_expandedINames.insert(child->iname); [this](WatchItem *child) { m_expandedINames.insert(child->iname); });
});
m_engine->updateLocals(); m_engine->updateLocals();
} }
}); });
addAction(menu, tr("Collapse All Children"), addAction(menu, tr("Collapse All Children"), item, [this, name = item ? item->iname : QString()] {
item,
[this, name = item->iname] {
if (auto item = findItem(name)) { if (auto item = findItem(name)) {
item->forFirstLevelChildren([this](WatchItem *child) { item->forFirstLevelChildren(
m_expandedINames.remove(child->iname); [this](WatchItem *child) { m_expandedINames.remove(child->iname); });
});
m_engine->updateLocals(); m_engine->updateLocals();
} }
}); });
@@ -1724,16 +1718,17 @@ bool WatchModel::contextMenuEvent(const ItemViewEvent &ev)
true, true,
[this] { copyToClipboard(editorContents()); }); [this] { copyToClipboard(editorContents()); });
addAction(menu, tr("Copy Current Value to Clipboard"), addAction(menu,
tr("Copy Current Value to Clipboard"),
item, item,
[this, name = item->iname] { [this, name = item ? item->iname : QString()] {
if (auto item = findItem(name)) if (auto item = findItem(name))
copyToClipboard(item->value); copyToClipboard(item->value);
}); });
// addAction(menu, tr("Copy Selected Rows to Clipboard"), // addAction(menu, tr("Copy Selected Rows to Clipboard"),
// selectionModel()->hasSelection(), // selectionModel()->hasSelection(),
// [this] { copyToClipboard(editorContents(selectionModel()->selectedRows())); }); // [this] { copyToClipboard(editorContents(selectionModel()->selectedRows())); });
addAction(menu, tr("Open View Contents in Editor"), addAction(menu, tr("Open View Contents in Editor"),
m_engine->debuggerActionsEnabled(), m_engine->debuggerActionsEnabled(),