fix: prevent potential crash in handleBezier due to invalid input

before, when the conf file contained anything other than a float in the 4 bezier curve generation points for annimations, it crashed Hyprland, which now returns an error message.
This commit is contained in:
tachyglossues 2024-05-26 11:11:29 +02:00 committed by GitHub
parent 553232a3e4
commit ed7cefdd3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1821,26 +1821,20 @@ std::optional<std::string> CConfigManager::handleBezier(const std::string& comma
const auto ARGS = CVarList(args); const auto ARGS = CVarList(args);
std::string bezierName = ARGS[0]; std::string bezierName = ARGS[0];
if (ARGS[1] == "" || ARGS[2] == "" || ARGS[3] == "" || ARGS[4] == "")
return "too few arguments";
if (ARGS[5]!= "")
return "too many arguments";
if (ARGS[1] == "") float p1x = 0, p1y = 0, p2x = 0, p2y = 0;
return "too few arguments"; try {
float p1x = std::stof(ARGS[1]); p1x = std::stof(ARGS[1]);
p1y = std::stof(ARGS[2]);
if (ARGS[2] == "") p2x = std::stof(ARGS[3]);
return "too few arguments"; p2y = std::stof(ARGS[4]);
float p1y = std::stof(ARGS[2]); } catch (const std::invalid_argument&) {
return "invalid argument";
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]);
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 {}; return {};