aboutsummaryrefslogtreecommitdiff
path: root/xcursor
diff options
context:
space:
mode:
authorValentin <vakevk+git@gmail.com>2020-08-30 11:13:19 +0200
committerSimon Ser <contact@emersion.fr>2020-09-01 11:58:56 +0200
commit65abd4e92af497bbe1ae1085fa16b1b811a3c652 (patch)
treed233c2ec02dbe5685e241ea3417e3e9ba17a092a /xcursor
parent8b744412aab11fe4997367adf1a714ef2cb3946e (diff)
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.
Diffstat (limited to 'xcursor')
-rw-r--r--xcursor/xcursor.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/xcursor/xcursor.c b/xcursor/xcursor.c
index aabef483..51ce8323 100644
--- a/xcursor/xcursor.c
+++ b/xcursor/xcursor.c
@@ -285,11 +285,12 @@ _XcursorReadUInt (XcursorFile *file, XcursorUInt *u)
return XcursorFalse;
if ((*file->read) (file, bytes, 4) != 4)
- return XcursorFalse;
- *u = ((bytes[0] << 0) |
- (bytes[1] << 8) |
- (bytes[2] << 16) |
- (bytes[3] << 24));
+ return XcursorFalse;
+
+ *u = ((XcursorUInt)(bytes[0]) << 0) |
+ ((XcursorUInt)(bytes[1]) << 8) |
+ ((XcursorUInt)(bytes[2]) << 16) |
+ ((XcursorUInt)(bytes[3]) << 24);
return XcursorTrue;
}