diff mbox

[3/2] misc: ubsan fixes

Message ID 20180126181448.GU9068@magnolia (mailing list archive)
State Accepted
Headers show

Commit Message

Darrick J. Wong Jan. 26, 2018, 6:14 p.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Fix a few things the undefined behavior sanitizer complained about.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 db/bit.c    |    4 ++--
 repair/sb.c |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Eric Sandeen Jan. 30, 2018, 4:47 p.m. UTC | #1
On 1/26/18 12:14 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Fix a few things the undefined behavior sanitizer complained about.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>


Reviewed-by: Eric Sandeen <sandeen@redhat.com>

> ---

>  db/bit.c    |    4 ++--
>  repair/sb.c |    4 ++--
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/db/bit.c b/db/bit.c
> index a20b6ba..bf8d80e 100644
> --- a/db/bit.c
> +++ b/db/bit.c
> @@ -112,11 +112,11 @@ getbitval(
>  #if __BYTE_ORDER == LITTLE_ENDIAN
>  			if (i == 0 && signext && nbits < 64)
>  				rval = -1LL << nbits;
> -			rval |= 1LL << (nbits - i - 1);
> +			rval |= 1ULL << (nbits - i - 1);
>  #else
>  			if ((i == (nbits - 1)) && signext && nbits < 64)
>  				rval |= (-1LL << nbits);
> -			rval |= 1LL << (nbits - i - 1);
> +			rval |= 1ULL << (nbits - i - 1);
>  #endif
>  		}
>  	}
> diff --git a/repair/sb.c b/repair/sb.c
> index f40cdea..3dc6538 100644
> --- a/repair/sb.c
> +++ b/repair/sb.c
> @@ -89,11 +89,11 @@ verify_sb_blocksize(xfs_sb_t *sb)
>  	/* check to make sure blocksize is legal 2^N, 9 <= N <= 16 */
>  	if (sb->sb_blocksize == 0)
>  		return XR_BAD_BLOCKSIZE;
> -	if (sb->sb_blocksize != (1 << sb->sb_blocklog))
> -		return XR_BAD_BLOCKLOG;
>  	if (sb->sb_blocklog < XFS_MIN_BLOCKSIZE_LOG ||
>  	    sb->sb_blocklog > XFS_MAX_BLOCKSIZE_LOG)
>  		return XR_BAD_BLOCKLOG;
> +	if (sb->sb_blocksize != (1 << sb->sb_blocklog))
> +		return XR_BAD_BLOCKLOG;
>  
>  	return 0;
>  }
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/db/bit.c b/db/bit.c
index a20b6ba..bf8d80e 100644
--- a/db/bit.c
+++ b/db/bit.c
@@ -112,11 +112,11 @@  getbitval(
 #if __BYTE_ORDER == LITTLE_ENDIAN
 			if (i == 0 && signext && nbits < 64)
 				rval = -1LL << nbits;
-			rval |= 1LL << (nbits - i - 1);
+			rval |= 1ULL << (nbits - i - 1);
 #else
 			if ((i == (nbits - 1)) && signext && nbits < 64)
 				rval |= (-1LL << nbits);
-			rval |= 1LL << (nbits - i - 1);
+			rval |= 1ULL << (nbits - i - 1);
 #endif
 		}
 	}
diff --git a/repair/sb.c b/repair/sb.c
index f40cdea..3dc6538 100644
--- a/repair/sb.c
+++ b/repair/sb.c
@@ -89,11 +89,11 @@  verify_sb_blocksize(xfs_sb_t *sb)
 	/* check to make sure blocksize is legal 2^N, 9 <= N <= 16 */
 	if (sb->sb_blocksize == 0)
 		return XR_BAD_BLOCKSIZE;
-	if (sb->sb_blocksize != (1 << sb->sb_blocklog))
-		return XR_BAD_BLOCKLOG;
 	if (sb->sb_blocklog < XFS_MIN_BLOCKSIZE_LOG ||
 	    sb->sb_blocklog > XFS_MAX_BLOCKSIZE_LOG)
 		return XR_BAD_BLOCKLOG;
+	if (sb->sb_blocksize != (1 << sb->sb_blocklog))
+		return XR_BAD_BLOCKLOG;
 
 	return 0;
 }