Skip to contentSkip to conversation

xfs_db: fix broken logic in error path

PATCH In review Darrick J. Wong 2 participants 2 messages Apr 27, 2023 – Apr 28, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_db: fix broken logic in error path

From: Darrick J. Wong <[email protected]>

smatch complains proceeding into the if body if leaf is a null pointer:

check.c:3614 process_leaf_node_dir_v2_int() warn: variable dereferenced before check 'leaf' (see line 3518)

However, the logic here is misleading and broken -- what we're trying to do is switch between the v4 and v5 variants of the directory check. We're using @leaf3 being a null pointer (or not) to determine v4 vs. v5, so the "!" part of the comparison is correct, but the variable used (leaf) is not.

---
 db/check.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
db/check.c +1 -1
index 964756d0..fdf1f6a1 100644
@@ -3452,7 +3452,7 @@ process_leaf_node_dir_v2_int(
 				 id->ino, dabno, stale,
 				 be16_to_cpu(leaf3->hdr.stale));
 		error++;
-	} else if (!leaf && stale != be16_to_cpu(leaf->hdr.stale)) {
+	} else if (!leaf3 && stale != be16_to_cpu(leaf->hdr.stale)) {
 		if (!sflag || v)
 			dbprintf(_("dir %lld block %d stale mismatch "
 				 "%d/%d\n"),
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

smatch complains proceeding into the if body if leaf is a null pointer:

check.c:3614 process_leaf_node_dir_v2_int() warn: variable dereferenced before check 'leaf' (see line 3518)

Quoted 7 lines

However, the logic here is misleading and broken -- what we're trying to do is switch between the v4 and v5 variants of the directory check. We're using @leaf3 being a null pointer (or not) to determine v4 vs. v5, so the "!" part of the comparison is correct, but the variable used (leaf) is not.

Looks correct.

Quoted 17 lines
---
 db/check.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
db/check.c +1 -1
index 964756d0..fdf1f6a1 100644
@@ -3452,7 +3452,7 @@ process_leaf_node_dir_v2_int(
 				 id->ino, dabno, stale,
 				 be16_to_cpu(leaf3->hdr.stale));
 		error++;
-	} else if (!leaf && stale != be16_to_cpu(leaf->hdr.stale)) {
+	} else if (!leaf3 && stale != be16_to_cpu(leaf->hdr.stale)) {
 		if (!sflag || v)
 			dbprintf(_("dir %lld block %d stale mismatch "
 				 "%d/%d\n"),
Signature · 1 line
Carlos Maiolino