]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
misc: fix ubsan warnings
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 9 Nov 2017 17:35:29 +0000 (11:35 -0600)
committerEric Sandeen <sandeen@redhat.com>
Thu, 9 Nov 2017 17:35:29 +0000 (11:35 -0600)
Fix all the things ubsan warned about.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
include/bitops.h
include/command.h
include/xfs_arch.h

index 44599a7843983f2ec49e78a207a95e465347bd36..7774950ad59c9fc2933fe14876162d2373628a36 100644 (file)
@@ -13,19 +13,19 @@ static inline int fls(int x)
        if (!x)
                return 0;
        if (!(x & 0xffff0000u)) {
-               x <<= 16;
+               x = (x & 0xffffu) << 16;
                r -= 16;
        }
        if (!(x & 0xff000000u)) {
-               x <<= 8;
+               x = (x & 0xffffffu) << 8;
                r -= 8;
        }
        if (!(x & 0xf0000000u)) {
-               x <<= 4;
+               x = (x & 0xfffffffu) << 4;
                r -= 4;
        }
        if (!(x & 0xc0000000u)) {
-               x <<= 2;
+               x = (x & 0x3fffffffu) << 2;
                r -= 2;
        }
        if (!(x & 0x80000000u)) {
index fb3f5c79b9912e7df9c64c062d7ca460a55d1f12..a7fe6eb01383f143577e970c99782dd934294209 100644 (file)
@@ -25,9 +25,9 @@
  * not iterate the command args function callout and so can be used
  * for functions like "help" that should only ever be run once.
  */
-#define CMD_FLAG_ONESHOT       (1<<31)
-#define CMD_FLAG_FOREIGN_OK    (1<<30) /* command not restricted to XFS */
-#define CMD_FLAG_LIBRARY       (1<<29) /* command provided by libxcmd */
+#define CMD_FLAG_ONESHOT       (1u << 31)
+#define CMD_FLAG_FOREIGN_OK    (1u << 30) /* command not restricted to XFS */
+#define CMD_FLAG_LIBRARY       (1u << 29) /* command provided by libxcmd */
 
 typedef int (*cfunc_t)(int argc, char **argv);
 typedef void (*helpfunc_t)(void);
index 186cadbab7f0b44be02d1ccc2396fec23627ebad..34fcd4dbfd98edacb171cbef2f2e5dfb4d251171 100644 (file)
@@ -253,7 +253,7 @@ static inline uint16_t get_unaligned_be16(void *p)
 static inline uint32_t get_unaligned_be32(void *p)
 {
        uint8_t *__p = p;
-        return __p[0] << 24 | __p[1] << 16 | __p[2] << 8 | __p[3];
+        return (uint32_t)__p[0] << 24 | __p[1] << 16 | __p[2] << 8 | __p[3];
 }
 
 static inline uint64_t get_unaligned_be64(void *p)