From 1ab6a81816f52c17be2138ba569256b5afc029f2 Mon Sep 17 00:00:00 2001 From: Valentin Date: Fri, 4 Sep 2020 12:15:03 +0200 Subject: [PATCH] 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 --- cursor/xcursor.c | 9 +++++---- 1 file 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; }