]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Use an unsigned type for bitmask values
authorBenjamin Kaduk <kaduk@mit.edu>
Mon, 16 Jun 2014 16:44:08 +0000 (12:44 -0400)
committerJeffrey Altman <jaltman@your-file-system.com>
Tue, 17 Jun 2014 15:48:18 +0000 (11:48 -0400)
As noted by clang -Wshift-sign-overflow, the expression "1<<31"
overflows the signed int type, giving undefined behavior.

Use an unsigned type to make the result of the shift defined
behavior by the C99 standard.

Also change an instance of "1<<31" that was checking for whether the
most significant bit was set, as it's still undefined behavior.

Change-Id: I8cf9443aa92470181044fc3b63d491da18ff5e34
Reviewed-on: http://gerrit.openafs.org/11301
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
src/dir/dir.c
src/ptserver/ptint.xg
src/rx/xdr_rec.c

index 08b9db51e24118fe32f25e715c1dca254eed0ecb..f930adced2e44bacd5668d98778189f445f199f1 100644 (file)
@@ -577,7 +577,7 @@ afs_dir_DirHash(char *string)
     tval = hval & (NHASHENT - 1);
     if (tval == 0)
        return tval;
-    else if (hval >= 1<<31)
+    else if (hval >= 1u<<31)
        tval = NHASHENT - tval;
     return tval;
 }
index fe6a2a30e9d7d82a2ef08d8cfab22167d069c966..e8ac46890208c4a5543b872912ece43415824193 100644 (file)
@@ -99,8 +99,8 @@ const PRUPDATE_IDHASH =       0x0010;
 
 /* These bits are used when calling SetFieldsEntry. */
 %#define PR_SF_ALLBITS   0xff          /* set all access bits */
-%#define PR_SF_NGROUPS (1<<31)         /* set field limiting group creation */
-%#define PR_SF_NUSERS  (1<<30)         /*  "  "  foreign users  "  */
+%#define PR_SF_NGROUPS (1u<<31)                /* set field limiting group creation */
+%#define PR_SF_NUSERS  (1u<<30)                /*  "  "  foreign users  "  */
 
 typedef char prname[PR_MAXNAMELEN];
 typedef prname namelist<>;
index f801d19406571e30145ab5ae61a352e6346f5928..9b6d656104d29335aed75cd4e88698665306834d 100644 (file)
@@ -61,7 +61,7 @@
  * meet the needs of xdr and rpc based on tcp.
  */
 
-#define LAST_FRAG ((afs_uint32)(1 << 31))
+#define LAST_FRAG ((afs_uint32)(1u << 31))
 
 typedef struct rec_strm {
     caddr_t tcp_handle;