diff options
author | Valentin <vakevk+git@gmail.com> | 2020-08-30 15:37:19 +0200 |
---|---|---|
committer | Valentin <vakevk+git@gmail.com> | 2020-08-30 15:37:19 +0200 |
commit | 204b6f130858ef038832887ea10488e7aed711a6 (patch) | |
tree | 0def27c11a05d6a879b88c963ef97ea7fba5dcac | |
parent | 448398a3b97a77648e90cc993597bafb2ad95eac (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.
-rw-r--r-- | src/file.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -161,11 +161,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; } |