Qt: Add some null checks.

Add some null checks identified by scan-build. Switch some dynamic_casts
to qobject_casts.

Change-Id: I2b97ee8cb71db4fc883b4081568f9a5db8af85b3
Reviewed-on: https://code.wireshark.org/review/35403
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
This commit is contained in:
Gerald Combs 2019-12-10 17:03:34 -08:00 committed by Alexis La Goutte
parent 3e0acea604
commit 90e80ac6af
2 changed files with 24 additions and 13 deletions

View File

@ -296,7 +296,7 @@ QWidget *InterfaceToolbar::createString(iface_toolbar_control *control)
void InterfaceToolbar::setWidgetValue(QWidget *widget, int command, QByteArray payload)
{
if (QComboBox *combobox = dynamic_cast<QComboBox *>(widget))
if (QComboBox *combobox = qobject_cast<QComboBox *>(widget))
{
combobox->blockSignals(true);
switch (command)
@ -362,7 +362,7 @@ void InterfaceToolbar::setWidgetValue(QWidget *widget, int command, QByteArray p
}
combobox->blockSignals(false);
}
else if (InterfaceToolbarLineEdit *lineedit = dynamic_cast<InterfaceToolbarLineEdit *>(widget))
else if (InterfaceToolbarLineEdit *lineedit = qobject_cast<InterfaceToolbarLineEdit *>(widget))
{
// We don't block signals here because changes are applied with enter or apply button,
// and we want InterfaceToolbarLineEdit to always syntax check the text.
@ -377,7 +377,7 @@ void InterfaceToolbar::setWidgetValue(QWidget *widget, int command, QByteArray p
break;
}
}
else if (QCheckBox *checkbox = dynamic_cast<QCheckBox *>(widget))
else if (QCheckBox *checkbox = qobject_cast<QCheckBox *>(widget))
{
checkbox->blockSignals(true);
switch (command)
@ -398,7 +398,7 @@ void InterfaceToolbar::setWidgetValue(QWidget *widget, int command, QByteArray p
}
checkbox->blockSignals(false);
}
else if (QPushButton *button = dynamic_cast<QPushButton *>(widget))
else if (QPushButton *button = qobject_cast<QPushButton *>(widget))
{
if ((command == commandControlSet) &&
widget->property(interface_role_property).toInt() == INTERFACE_ROLE_CONTROL)
@ -410,7 +410,11 @@ void InterfaceToolbar::setWidgetValue(QWidget *widget, int command, QByteArray p
void InterfaceToolbar::setInterfaceValue(QString ifname, QWidget *widget, int num, int command, QByteArray payload)
{
if (dynamic_cast<QComboBox *>(widget))
if (!widget) {
return;
}
if (qobject_cast<QComboBox *>(widget))
{
switch (command)
{
@ -454,7 +458,7 @@ void InterfaceToolbar::setInterfaceValue(QString ifname, QWidget *widget, int nu
break;
}
}
else if (dynamic_cast<InterfaceToolbarLineEdit *>(widget))
else if (qobject_cast<InterfaceToolbarLineEdit *>(widget))
{
switch (command)
{

View File

@ -143,14 +143,19 @@ void ColumnTypeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model
else if (index.column() == ColumnListModel::COL_FIELDS)
{
FieldFilterEdit * ffe = qobject_cast<FieldFilterEdit *>(editor);
if (ffe && ffe->checkFilter())
if (ffe)
{
QModelIndex typeIndex = index.sibling(index.row(), ColumnListModel::COL_TYPE);
model->setData(typeIndex, COL_CUSTOM, Qt::EditRole);
model->setData(index, ffe->text(), Qt::EditRole);
if (ffe->checkFilter())
{
QModelIndex typeIndex = index.sibling(index.row(), ColumnListModel::COL_TYPE);
model->setData(typeIndex, COL_CUSTOM, Qt::EditRole);
model->setData(index, ffe->text(), Qt::EditRole);
}
else
{
ffe->setText(index.data().toString());
}
}
else
ffe->setText(index.data().toString());
if (index.data().toString().length() == 0)
{
@ -176,8 +181,10 @@ void ColumnTypeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model
model->setData(typeIndex, COL_CUSTOM, Qt::EditRole);
model->setData(index, sle->text(), Qt::EditRole);
}
else
else if (sle)
{
sle->setText(index.data().toString());
}
if (index.data().toString().length() == 0)
{