Fix OOB read when parsing empty string as float
I really don't like how the only way to return with an error from ParseFloatProperty is via an exception >_> Also do a range check on airTemp only if isValid is true, otherwise it's uninitialized.
This commit is contained in:
parent
a8d2b269b1
commit
d75e4ccb2e
@ -25,6 +25,10 @@
|
|||||||
|
|
||||||
void ParseFloatProperty(String value, float &out)
|
void ParseFloatProperty(String value, float &out)
|
||||||
{
|
{
|
||||||
|
if (!value.size())
|
||||||
|
{
|
||||||
|
throw std::out_of_range("empty string");
|
||||||
|
}
|
||||||
if (value.EndsWith("C"))
|
if (value.EndsWith("C"))
|
||||||
{
|
{
|
||||||
float v = value.SubstrFromEnd(1).ToNumber<float>();
|
float v = value.SubstrFromEnd(1).ToNumber<float>();
|
||||||
|
@ -476,7 +476,7 @@ void OptionsView::UpdateAirTemp(String temp, bool isDefocus)
|
|||||||
ambientAirTemp->SetText(sb.Build());
|
ambientAirTemp->SetText(sb.Build());
|
||||||
}
|
}
|
||||||
// Out of range temperatures are invalid, preview should go away
|
// Out of range temperatures are invalid, preview should go away
|
||||||
else if (airTemp < MIN_TEMP || airTemp > MAX_TEMP)
|
else if (isValid && (airTemp < MIN_TEMP || airTemp > MAX_TEMP))
|
||||||
isValid = false;
|
isValid = false;
|
||||||
|
|
||||||
// If valid, set temp
|
// If valid, set temp
|
||||||
|
Loading…
Reference in New Issue
Block a user