config: prevent crash on invalid numeric values

This commit is contained in:
B2krobbery 2026-04-29 20:00:26 +05:30
parent d332164dd9
commit 4b362ac9d3

View file

@ -89,7 +89,12 @@ static Hyprlang::CParseResult configHandleLayoutOption(const char* v, void** dat
rhs.pop_back();
}
DATA->m_vValues = Hyprutils::Math::Vector2D{std::stof(lhs), std::stof(rhs)};
try {
DATA->m_vValues = Hyprutils::Math::Vector2D{std::stof(lhs), std::stof(rhs)};
} catch (const std::exception&) {
result.setError(std::format("invalid layout values: {}", VALUE).c_str());
return result;
}
return result;
}
@ -595,34 +600,41 @@ std::optional<std::string> CConfigManager::handleSource(const std::string& comma
}
std::optional<std::string> CConfigManager::handleBezier(const std::string& command, const std::string& args) {
const auto ARGS = CVarList(args);
const auto ARGS = CVarList(args);
std::string bezierName = ARGS[0];
if (ARGS[1] == "")
return "too few arguments";
float p1x = std::stof(ARGS[1]);
if (ARGS[2] == "")
return "too few arguments";
float p1y = std::stof(ARGS[2]);
if (ARGS[3] == "")
return "too few arguments";
float p2x = std::stof(ARGS[3]);
if (ARGS[4] == "")
return "too few arguments";
float p2y = std::stof(ARGS[4]);
float p1x, p1y, p2x, p2y;
try {
p1x = std::stof(ARGS[1]);
p1y = std::stof(ARGS[2]);
p2x = std::stof(ARGS[3]);
p2y = std::stof(ARGS[4]);
} catch (const std::exception&) {
return "invalid bezier arguments";
}
if (ARGS[5] != "")
return "too many arguments";
g_pAnimationManager->addBezierWithName(bezierName, Vector2D(p1x, p1y), Vector2D(p2x, p2y));
g_pAnimationManager->addBezierWithName(
bezierName,
Vector2D(p1x, p1y),
Vector2D(p2x, p2y)
);
return {};
}
std::optional<std::string> CConfigManager::handleAnimation(const std::string& command, const std::string& args) {
const auto ARGS = CVarList(args);