aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/helpers
diff options
context:
space:
mode:
authorTom Englund <[email protected]>2024-08-26 14:08:30 +0200
committerGitHub <[email protected]>2024-08-26 14:08:30 +0200
commit9c5a37a797ea1f1829859ab5b07016b2f27f739c (patch)
tree709cd6abe37debb1970081a4466188f7084e975b /src/helpers
parentca85455a8ed5dbe920a47c1a48de1dd993446481 (diff)
downloadHyprland-9c5a37a797ea1f1829859ab5b07016b2f27f739c.tar.gz
Hyprland-9c5a37a797ea1f1829859ab5b07016b2f27f739c.zip
build: fix 32bit builds (#7510)
ensure the correct type is passed to std::clamp and std::max int64_t is different on 64bit compared to 32bit, also in presentationtime tv_sec is __time_t and on 32bit its a 32bit type so right shift count >= width of type. so only bit shift on 64bit. and avoid potential nullptr deref in the for loops, check for .end() before *it <= endID.
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/MiscFunctions.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp
index 86f24e3a..ef319946 100644
--- a/src/helpers/MiscFunctions.cpp
+++ b/src/helpers/MiscFunctions.cpp
@@ -353,13 +353,13 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) {
char walkDir = in[1];
// sanitize. 0 means invalid oob in -
- predictedWSID = std::max(predictedWSID, 0L);
+ predictedWSID = std::max(predictedWSID, static_cast<int64_t>(0));
// Count how many invalidWSes are in between (how bad the prediction was)
WORKSPACEID beginID = in[1] == '+' ? activeWSID + 1 : predictedWSID;
WORKSPACEID endID = in[1] == '+' ? predictedWSID : activeWSID;
auto begin = invalidWSes.upper_bound(beginID - 1); // upper_bound is >, we want >=
- for (auto it = begin; *it <= endID && it != invalidWSes.end(); it++) {
+ for (auto it = begin; it != invalidWSes.end() && *it <= endID; it++) {
remainingWSes++;
}
@@ -376,7 +376,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) {
}
currentItem += remains;
- currentItem = std::max(currentItem, 0UL);
+ currentItem = std::max(currentItem, static_cast<size_t>(0));
if (currentItem >= namedWSes.size()) {
// At the seam between namedWSes and normal WSes. Behave like r+[diff] at imaginary ws 0
size_t diff = currentItem - (namedWSes.size() - 1);
@@ -384,7 +384,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) {
WORKSPACEID beginID = 1;
WORKSPACEID endID = predictedWSID;
auto begin = invalidWSes.upper_bound(beginID - 1); // upper_bound is >, we want >=
- for (auto it = begin; *it <= endID && it != invalidWSes.end(); it++) {
+ for (auto it = begin; it != invalidWSes.end() && *it <= endID; it++) {
remainingWSes++;
}
walkDir = '+';
@@ -413,7 +413,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) {
// Need remainingWSes more
auto namedWSIdx = namedWSes.size() - remainingWSes;
// Sanitze
- namedWSIdx = std::clamp(namedWSIdx, 0UL, namedWSes.size() - 1);
+ namedWSIdx = std::clamp(namedWSIdx, static_cast<size_t>(0), namedWSes.size() - static_cast<size_t>(1));
finalWSID = namedWSes[namedWSIdx];
} else {
// Couldn't find valid workspace in negative direction, search last first one back up positive direction