Fixed: stoi 0 literal pointer to nullptr and added more clamping for gradient array access

This commit is contained in:
aristocratos
2021-09-21 17:21:42 +02:00
parent fe089038e0
commit 8d3e4575be
3 changed files with 20 additions and 19 deletions

View File

@@ -159,7 +159,7 @@ namespace Theme {
string pre = Fx::e + (depth == "fg" ? "38" : "48") + ";" + (t_to_256 ? "5;" : "2;");
if (hexa.size() == 2) {
int h_int = stoi(hexa, 0, 16);
int h_int = stoi(hexa, nullptr, 16);
if (t_to_256) {
return pre + to_string(truecolor_to_256(h_int, h_int, h_int)) + "m";
} else {
@@ -170,14 +170,14 @@ namespace Theme {
else if (hexa.size() == 6) {
if (t_to_256) {
return pre + to_string(truecolor_to_256(
stoi(hexa.substr(0, 2), 0, 16),
stoi(hexa.substr(2, 2), 0, 16),
stoi(hexa.substr(4, 2), 0, 16))) + "m";
stoi(hexa.substr(0, 2), nullptr, 16),
stoi(hexa.substr(2, 2), nullptr, 16),
stoi(hexa.substr(4, 2), nullptr, 16))) + "m";
} else {
return pre +
to_string(stoi(hexa.substr(0, 2), 0, 16)) + ";" +
to_string(stoi(hexa.substr(2, 2), 0, 16)) + ";" +
to_string(stoi(hexa.substr(4, 2), 0, 16)) + "m";
to_string(stoi(hexa.substr(0, 2), nullptr, 16)) + ";" +
to_string(stoi(hexa.substr(2, 2), nullptr, 16)) + ";" +
to_string(stoi(hexa.substr(4, 2), nullptr, 16)) + "m";
}
}
else Logger::error("Invalid size of hex value: " + hexa);
@@ -203,14 +203,14 @@ namespace Theme {
for (auto& c : hexa) if (not isxdigit(c)) return array<int, 3>{-1, -1, -1};
if (hexa.size() == 2) {
int h_int = stoi(hexa, 0, 16);
int h_int = stoi(hexa, nullptr, 16);
return array<int, 3>{h_int, h_int, h_int};
}
else if (hexa.size() == 6) {
return array<int, 3>{
stoi(hexa.substr(0, 2), 0, 16),
stoi(hexa.substr(2, 2), 0, 16),
stoi(hexa.substr(4, 2), 0, 16)
stoi(hexa.substr(0, 2), nullptr, 16),
stoi(hexa.substr(2, 2), nullptr, 16),
stoi(hexa.substr(4, 2), nullptr, 16)
};
}
}
@@ -434,4 +434,4 @@ namespace Theme {
Fx::reset = Fx::reset_base + Term::fg + Term::bg;
}
}
}