From d704f1d4dc3fca4d903c443130374da2284f3f15 Mon Sep 17 00:00:00 2001 From: Benjamin Kaduk Date: Mon, 16 Jun 2014 12:44:08 -0400 Subject: [PATCH] Use an unsigned type for bitmask values 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 Reviewed-by: Chas Williams - CONTRACTOR Reviewed-by: Jeffrey Altman --- src/dir/dir.c | 2 +- src/ptserver/ptint.xg | 4 ++-- src/rx/xdr_rec.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dir/dir.c b/src/dir/dir.c index 08b9db51e..f930adced 100644 --- a/src/dir/dir.c +++ b/src/dir/dir.c @@ -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; } diff --git a/src/ptserver/ptint.xg b/src/ptserver/ptint.xg index fe6a2a30e..e8ac46890 100644 --- a/src/ptserver/ptint.xg +++ b/src/ptserver/ptint.xg @@ -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<>; diff --git a/src/rx/xdr_rec.c b/src/rx/xdr_rec.c index f801d1940..9b6d65610 100644 --- a/src/rx/xdr_rec.c +++ b/src/rx/xdr_rec.c @@ -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; -- 2.39.5