Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Fix possible crash with invalid nCustomFeeRadio in QSettings (achow101, TheBlueMatt) #11332
Conversation
jonasschnelli
added
the
GUI
label
Sep 14, 2017
| - ui->groupCustomFee->button((int)std::max(0, std::min(1, settings.value("nCustomFeeRadio").toInt())))->setChecked(true); | ||
| + QAbstractButton *groupCustomFee = ui->groupCustomFee->button((int)std::max(0, std::min(1, settings.value("nCustomFeeRadio").toInt()))); | ||
| + if (groupCustomFee) { | ||
| + groupCustomFee->setChecked(true); |
laanwj
Sep 14, 2017
Owner
- If you add the null check, do you still need the awkward
std::max(0, std::min(1,construction? after all, button is defined to return 0 if no such button exists http://doc.qt.io/qt-4.8/qbuttongroup.html#button - Wouldn't it be better to remove the group completely if there is only one choice?
|
Commit message needs to credit @achow101 for finding this :) |
| @@ -128,7 +128,10 @@ SendCoinsDialog::SendCoinsDialog(const PlatformStyle *_platformStyle, QWidget *p | ||
| ui->groupFee->setId(ui->radioCustomFee, 1); | ||
| ui->groupFee->button((int)std::max(0, std::min(1, settings.value("nFeeRadio").toInt())))->setChecked(true); | ||
| ui->groupCustomFee->setId(ui->radioCustomPerKilobyte, 0); | ||
| - ui->groupCustomFee->button((int)std::max(0, std::min(1, settings.value("nCustomFeeRadio").toInt())))->setChecked(true); | ||
| + QAbstractButton *groupCustomFee = ui->groupCustomFee->button((int)std::max(0, std::min(1, settings.value("nCustomFeeRadio").toInt()))); |
laanwj
Sep 14, 2017
Owner
groupCustomFee might not be the best name for this variable, after all it's a button not a group (also snake_case?)
|
Updated with the simpler solution by @TheBlueMatt (from 6ba2214). Credited @achow101. |
|
This is a back-portable short fix and for 0.16 we should consider removing the group entirely (over further overhaul the custom fee settings) |
jonasschnelli
added
the
Needs backport
label
Sep 14, 2017
|
utACK |
|
utACK |
|
utACK |
|
utACK |
achow101
referenced this pull request
Sep 15, 2017
Merged
qt: Remove custom fee radio group and remove nCustomFeeRadio setting #11334
|
utACK cdaf3a1 |
jonasschnelli commentedSep 14, 2017
•
Edited 1 time
-
jonasschnelli
Sep 14, 2017
QButtonGroup->button()may return a nullptr.Accessing the object directly with
setCheckedseems fragile.This is a simple fix to ensure to never call a button out of bounds (nullptr).
There are probably other places where a sanity check for
QSettingsare required.Found by @achow101.
Code by @TheBlueMatt.