summaryrefslogtreecommitdiff
path: root/cursor
diff options
context:
space:
mode:
authorValentin <vakevk+git@gmail.com>2020-09-04 12:15:03 +0200
committerValentin <vakevk+git@gmail.com>2020-09-04 12:27:33 +0200
commit1ab6a81816f52c17be2138ba569256b5afc029f2 (patch)
tree7bab6d7d1d36eb32538ae8e0b4a6ff5280b36c84 /cursor
parentfc3beac71f631fb16ee2257e9a6c9ec07cd0c90d (diff)
downloadwayland-1ab6a81816f52c17be2138ba569256b5afc029f2.tar.gz
Fix undefined behavior
Without the casts the bytes accesses get converted to int. but int is not guaranteed to be 4 bytes large. Even when it is 4 bytes large `bytes[3] << 24` does not fit because int is signed. Signed-off-by: Valentin Kettner <vakevk@gmail.com>
Diffstat (limited to 'cursor')
-rw-r--r--cursor/xcursor.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/cursor/xcursor.c b/cursor/xcursor.c
index 689c702..1f1360f 100644
--- a/cursor/xcursor.c
+++ b/cursor/xcursor.c
@@ -285,10 +285,11 @@ _XcursorReadUInt (XcursorFile *file, XcursorUInt *u)
if ((*file->read) (file, bytes, 4) != 4)
return XcursorFalse;
- *u = ((bytes[0] << 0) |
- (bytes[1] << 8) |
- (bytes[2] << 16) |
- (bytes[3] << 24));
+
+ *u = ((XcursorUInt)(bytes[0]) << 0) |
+ ((XcursorUInt)(bytes[1]) << 8) |
+ ((XcursorUInt)(bytes[2]) << 16) |
+ ((XcursorUInt)(bytes[3]) << 24);
return XcursorTrue;
}