Avoid potential null pointer dereference in TransactionView::exportClicked().
Issue introduced in commit 8969828d069e4e55108618a493749535edc12ec7.
Avoid potential null pointer dereference in TransactionView::exportClicked().
Issue introduced in commit 8969828d069e4e55108618a493749535edc12ec7.
354 | @@ -355,7 +355,11 @@ void TransactionView::exportClicked() 355 | writer.addColumn(tr("Type"), TransactionTableModel::Type, Qt::EditRole); 356 | writer.addColumn(tr("Label"), 0, TransactionTableModel::LabelRole); 357 | writer.addColumn(tr("Address"), 0, TransactionTableModel::AddressRole); 358 | - writer.addColumn(BitcoinUnits::getAmountColumnTitle(model->getOptionsModel()->getDisplayUnit()), 0, TransactionTableModel::FormattedAmountRole); 359 | + if (model && model->getOptionsModel()) {
In case model or model->getOptionsModel() is not set, there's no reason to continue here - there's no data to export.
Might as well return from the function early if so.
@laanwj Fixed! Looks good? Is an error message dialog necessary?
Is an error message dialog necessary?
That's not necessary. It's fine for the export to do nothing in that case.
A bit of context might be needed for this change – I assumed model can be NULL when entering exportClicked() due to this check:
if (model && model->haveWatchOnly())
writer.addColumn(tr("Watch-only"), TransactionTableModel::Watchonly);
Let me know if that assumption is incorrect :-)
In normal use that shouldn't happen. However the view class should be able to work (at least: not crash) with a NULL model, for UI-only testing.
@laanwj OK, thanks for the clarification!
utACK fd9599b1358a314b073a9ca0a68ca8037915d91d (runtime protection is always good).
Though I having a hard time finding a possibility how the user could press the "Export" button while not having a walletmodel attached to the TransactionView.