Sanitize con and window rect dimensions

Make sure they're neither zero (prohibited by X11) nor overflown during
subtraction.
This commit is contained in:
Albert Safin
2020-02-19 00:48:31 +00:00
committed by Orestis Floros
parent 1f0c628cde
commit e6ca7ca06f
3 changed files with 11 additions and 0 deletions

View File

@ -53,6 +53,12 @@ Rect rect_sub(Rect a, Rect b) {
a.height - b.height};
}
Rect rect_sanitize_dimensions(Rect rect) {
rect.width = (int32_t)rect.width <= 0 ? 1 : rect.width;
rect.height = (int32_t)rect.height <= 0 ? 1 : rect.height;
return rect;
}
bool rect_equals(Rect a, Rect b) {
return a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height;
}