]> git.sur5r.net Git - i3/i3/commitdiff
Fixes for undefined behaviour on signed shift (#3453)
authorAlan Barr <a.barr@outlook.com>
Sat, 13 Oct 2018 18:04:40 +0000 (19:04 +0100)
committerOrestis <orestisf1993@gmail.com>
Sat, 13 Oct 2018 18:04:40 +0000 (21:04 +0300)
Fixes for undefined behaviour on signed shift

Change literal 1 to unsigned to allow safe bitshift of 31.
Caught by cppcheck.

Make 0xFF unsigned to prevent a left shift into signed bit.
Spotted by @orestisf1993

i3bar/src/ipc.c
include/i3/ipc.h
libi3/get_colorpixel.c

index 56fe279899c442572c7f8ba99d2f60b154a302b9..9a7fb21eb401038c1a63376d36a2874ddc3d4a25 100644 (file)
@@ -278,8 +278,8 @@ void got_data(struct ev_loop *loop, ev_io *watcher, int events) {
     buffer[size] = '\0';
 
     /* And call the callback (indexed by the type) */
-    if (type & (1 << 31)) {
-        type ^= 1 << 31;
+    if (type & (1UL << 31)) {
+        type ^= 1UL << 31;
         event_handlers[type](buffer);
     } else {
         if (reply_handlers[type])
index 0c57f7fdf40c51541af0ca735b1e54ad63e7df4b..884a0cf635c75985ef1bebd1a689be9039d48556 100644 (file)
@@ -87,7 +87,7 @@ typedef struct i3_ipc_header {
  * Events from i3 to clients. Events have the first bit set high.
  *
  */
-#define I3_IPC_EVENT_MASK (1 << 31)
+#define I3_IPC_EVENT_MASK (1UL << 31)
 
 /* The workspace event will be triggered upon changes in the workspace list */
 #define I3_IPC_EVENT_WORKSPACE (I3_IPC_EVENT_MASK | 0)
index afba202b276886c950b5b6c20f1677a00a2c3e69..49a9e3b40c3486e269bc565f8f1b7c2dec6f732a 100644 (file)
@@ -43,7 +43,7 @@ uint32_t get_colorpixel(const char *hex) {
 
     /* Shortcut: if our screen is true color, no need to do a roundtrip to X11 */
     if (root_screen == NULL || root_screen->root_depth == 24 || root_screen->root_depth == 32) {
-        return (0xFF << 24) | (r << 16 | g << 8 | b);
+        return (0xFFUL << 24) | (r << 16 | g << 8 | b);
     }
 
     /* Lookup this colorpixel in the cache */