From 8ae8e0f0a5403490729988754f2848f8f7afc930 Mon Sep 17 00:00:00 2001 From: Leland Lucius Date: Thu, 28 May 2020 20:09:14 -0500 Subject: [PATCH] Bug 2458 - Possible crash when clearing text field in Gain dialog --- src/widgets/ASlider.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/widgets/ASlider.cpp b/src/widgets/ASlider.cpp index 6db18a112..617423bed 100644 --- a/src/widgets/ASlider.cpp +++ b/src/widgets/ASlider.cpp @@ -322,16 +322,25 @@ bool SliderDialog::TransferDataToWindow() bool SliderDialog::TransferDataFromWindow() { - double value; + // Bug #2458 + // + // If the user clears the text control, the ToDouble below will NOT set "value" + // since it checks the length of the incoming string and bypasses setting it if + // it's empty. So initialize "value" for good measure and check the return value + // of ToDouble for success before using "value". + double value = 0.0; - mTextCtrl->GetValue().ToDouble(&value); - if (mStyle == DB_SLIDER) - value = DB_TO_LINEAR(value); - mSlider->Set(value); - if (mpOrigin) { - mpOrigin->Set(value); - mpOrigin->SendUpdate(value); + if (mTextCtrl->GetValue().ToDouble(&value)) + { + if (mStyle == DB_SLIDER) + value = DB_TO_LINEAR(value); + mSlider->Set(value); + if (mpOrigin) { + mpOrigin->Set(value); + mpOrigin->SendUpdate(value); + } } + return true; }