Skip to contentSkip to conversation

jfs: avoid -Wtautological-constant-out-of-range-compare warning again

PATCH In review Arnd Bergmann 2 participants 2 messages Mar 16 JFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 jfs: avoid -Wtautological-constant-out-of-range-compare warning again

From: Arnd Bergmann <[email protected]>

The comparison of an __s8 value against DTPAGEMAXSLOT is still trivially true, causing a harmless (default disabled) warning with clang:

fs/jfs/jfs_dtree.c:4419:25: error: result of comparison of constant 128 with expression of type 's8' (aka 'signed char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]

 4419 |                                         p->header.freelist >= DTPAGEMAXSLOT)) {
      |                                         ~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~

I previously worked around two of these in commit 7833570dae83 ("jfs: avoid -Wtautological-constant-out-of-range-compare warning"), but now a new one has come up, so address the same way by dropping the redundant range check.

Fixes 119e448bb50a ("jfs: add dtpage integrity check to prevent index/pointer overflows")
---
 fs/jfs/jfs_dtree.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/jfs/jfs_dtree.c +1 -2
index 7669e268fe35..a32c78d1c416 100644
@@ -4415,8 +4415,7 @@ bool check_dtpage(dtpage_t *p)
 		/* When there are free slots, freelist must be a valid slot index in
 		 * 1~DTROOTMAXSLOT-1(since slot[0] is occupied by the header).
 		 */
-		if (unlikely(p->header.freelist < 1 ||
-					p->header.freelist >= DTPAGEMAXSLOT)) {
+		if (unlikely(p->header.freelist < 1)) {
 			jfs_err("Bad freelist:%d in dtpage\n", p->header.freelist);
 			return false;
 		}
Signature · 1 line
2.39.5
#1 lore raw
Quoted 5 lines · Arnd Bergmann via Jfs-discussion

From: Arnd Bergmann <[email protected]>

The comparison of an __s8 value against DTPAGEMAXSLOT is still trivially true, causing a harmless (default disabled) warning with clang:

Quoted 7 lines

fs/jfs/jfs_dtree.c:4419:25: error: result of comparison of constant 128 with expression of type 's8' (aka 'signed char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]

  4419 |                                         p->header.freelist >= DTPAGEMAXSLOT)) {
       |                                         ~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~

I previously worked around two of these in commit 7833570dae83 ("jfs: avoid -Wtautological-constant-out-of-range-compare warning"), but now a new one has come up, so address the same way by dropping the redundant range check.

Thanks. I'm going to remove the comment above it as well, since it really isn't helpful.

Quoted 21 lines
Fixes 119e448bb50a ("jfs: add dtpage integrity check to prevent index/pointer overflows")
---
  fs/jfs/jfs_dtree.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
fs/jfs/jfs_dtree.c +1 -2
index 7669e268fe35..a32c78d1c416 100644
@@ -4415,8 +4415,7 @@ bool check_dtpage(dtpage_t *p)
  		/* When there are free slots, freelist must be a valid slot index in
  		 * 1~DTROOTMAXSLOT-1(since slot[0] is occupied by the header).
  		 */
-		if (unlikely(p->header.freelist < 1 ||
-					p->header.freelist >= DTPAGEMAXSLOT)) {
+		if (unlikely(p->header.freelist < 1)) {
  			jfs_err("Bad freelist:%d in dtpage\n", p->header.freelist);
  			return false;
  		}