Don't crash for empty string config

Fixes https://github.com/scorpion-26/gBar/issues/49
This commit is contained in:
scorpion-26 2023-09-07 18:48:28 +02:00
parent 0812c3680f
commit b215dfb145

View file

@ -127,7 +127,14 @@ void AddConfigVar(const std::string& propertyName, T& propertyToSet, std::string
std::string_view value = line.substr(colon + 1); std::string_view value = line.substr(colon + 1);
size_t beginValue = value.find_first_not_of(whitespace); size_t beginValue = value.find_first_not_of(whitespace);
size_t endValue = value.find_last_not_of(whitespace); size_t endValue = value.find_last_not_of(whitespace);
if (beginValue == std::string::npos || endValue == std::string::npos)
{
value = "";
}
else
{
value = value.substr(beginValue, endValue - beginValue + 1); value = value.substr(beginValue, endValue - beginValue + 1);
}
// Set value // Set value
ApplyProperty(propertyToSet, value); ApplyProperty(propertyToSet, value);