[PATCH V2] xfsprogs: use ASSERT_ALWAYS for impossible switch case

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The original reason for the expletive below has been lost
in the mists of time, but at any rate, ASSERT() goes away in
libxfs, and this leads static analysis checkers to believe that
XFS_BTNUM_MAX is possible, and that we might overflow an array
later when using it as an index.

We can shut this up and mark it as truly impossible by adding
a userspace definition for ASSERT_ALWAYS and using it.

Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>
---

V2: do it in a kernel-compatible way.

diff --git a/include/xfs_btree.h b/include/xfs_btree.h
index 2590d40..f24f787 100644
--- a/include/xfs_btree.h
+++ b/include/xfs_btree.h
@@ -69,7 +69,7 @@ do {    \
 	case XFS_BTNUM_BMAP: __XFS_BTREE_STATS_INC(bmbt, stat); break;	\
 	case XFS_BTNUM_INO: __XFS_BTREE_STATS_INC(ibt, stat); break;	\
 	case XFS_BTNUM_FINO: __XFS_BTREE_STATS_INC(fibt, stat); break;	\
-	case XFS_BTNUM_MAX: ASSERT(0); /* fucking gcc */ ; break;	\
+	case XFS_BTNUM_MAX: ASSERT_ALWAYS(0); /* fucking gcc */ ; break; \
 	}       \
 } while (0)
 
@@ -83,7 +83,7 @@ do {    \
 	case XFS_BTNUM_BMAP: __XFS_BTREE_STATS_ADD(bmbt, stat, val); break; \
 	case XFS_BTNUM_INO: __XFS_BTREE_STATS_ADD(ibt, stat, val); break; \
 	case XFS_BTNUM_FINO: __XFS_BTREE_STATS_ADD(fibt, stat, val); break; \
-	case XFS_BTNUM_MAX: ASSERT(0); /* fucking gcc */ ; break;	\
+	case XFS_BTNUM_MAX: ASSERT_ALWAYS(0); /* fucking gcc */ ; break; \
 	}       \
 } while (0)
 
diff --git a/libxfs/xfs.h b/libxfs/xfs.h
index 30a316d..81d7cd9 100644
--- a/libxfs/xfs.h
+++ b/libxfs/xfs.h
@@ -48,6 +48,10 @@
 #undef ASSERT
 #define ASSERT(ex) assert(ex)
 
+#undef ASSERT_ALWAYS
+#define ASSERT_ALWAYS(ex) \
+	(unlikely(ex) ? (void)0 : abort())
+
 typedef __uint32_t		uint_t;
 typedef __uint32_t		inst_t;		/* an instruction */
 

_______________________________________________
xfs mailing list
xfs@xxxxxxxxxxx
http://oss.sgi.com/mailman/listinfo/xfs




[Index of Archives]     [Linux XFS Devel]     [Linux Filesystem Development]     [Filesystem Testing]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux