aboutsummaryrefslogtreecommitdiffstats
path: root/tests/zfs-tests/cmd
diff options
context:
space:
mode:
authorToomas Soome <[email protected]>2022-09-28 03:09:21 +0300
committerGitHub <[email protected]>2022-09-27 17:09:21 -0700
commitaf65073a075b162ccf6e3dd8fb925f29d5743ca3 (patch)
tree97c1a5afafd15f09c14197eb2670b2bc9c9119c1 /tests/zfs-tests/cmd
parente872ea16f260fc62a98a46ed270a28f3590916c3 (diff)
btree_test: smatch did detect few issues
Add missing header. Properly ignore return values. Memory leak/unchecked malloc. We do allocate a bit too early (and fail to validate the result). From this, smatch is angry when we overwrite the value of 'node' later. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Igor Kozhukhov <[email protected]> Reviewed-by: Richard Yao <[email protected]> Signed-off-by: Toomas Soome <[email protected]> Closes #13941
Diffstat (limited to 'tests/zfs-tests/cmd')
-rw-r--r--tests/zfs-tests/cmd/btree_test.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/tests/zfs-tests/cmd/btree_test.c b/tests/zfs-tests/cmd/btree_test.c
index 456a36f31..4e2023003 100644
--- a/tests/zfs-tests/cmd/btree_test.c
+++ b/tests/zfs-tests/cmd/btree_test.c
@@ -15,6 +15,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/avl.h>
#include <sys/btree.h>
#include <sys/time.h>
@@ -164,7 +165,7 @@ find_without_index(zfs_btree_t *bt, char *why)
zfs_btree_add(bt, &i);
if ((p = (u_longlong_t *)zfs_btree_find(bt, &i, NULL)) == NULL ||
*p != i) {
- snprintf(why, BUFSIZE, "Unexpectedly found %llu\n",
+ (void) snprintf(why, BUFSIZE, "Unexpectedly found %llu\n",
p == NULL ? 0 : *p);
return (1);
}
@@ -172,7 +173,7 @@ find_without_index(zfs_btree_t *bt, char *why)
i++;
if ((p = (u_longlong_t *)zfs_btree_find(bt, &i, NULL)) != NULL) {
- snprintf(why, BUFSIZE, "Found bad value: %llu\n", *p);
+ (void) snprintf(why, BUFSIZE, "Found bad value: %llu\n", *p);
return (1);
}
@@ -189,10 +190,10 @@ insert_find_remove(zfs_btree_t *bt, char *why)
/* Insert 'i' into the tree, and attempt to find it again. */
zfs_btree_add(bt, &i);
if ((p = (u_longlong_t *)zfs_btree_find(bt, &i, &bt_idx)) == NULL) {
- snprintf(why, BUFSIZE, "Didn't find value in tree\n");
+ (void) snprintf(why, BUFSIZE, "Didn't find value in tree\n");
return (1);
} else if (*p != i) {
- snprintf(why, BUFSIZE, "Found (%llu) in tree\n", *p);
+ (void) snprintf(why, BUFSIZE, "Found (%llu) in tree\n", *p);
return (1);
}
ASSERT3S(zfs_btree_numnodes(bt), ==, 1);
@@ -201,7 +202,8 @@ insert_find_remove(zfs_btree_t *bt, char *why)
/* Remove 'i' from the tree, and verify it is not found. */
zfs_btree_remove(bt, &i);
if ((p = (u_longlong_t *)zfs_btree_find(bt, &i, &bt_idx)) != NULL) {
- snprintf(why, BUFSIZE, "Found removed value (%llu)\n", *p);
+ (void) snprintf(why, BUFSIZE,
+ "Found removed value (%llu)\n", *p);
return (1);
}
ASSERT3S(zfs_btree_numnodes(bt), ==, 0);
@@ -240,9 +242,12 @@ drain_tree(zfs_btree_t *bt, char *why)
zfs_btree_add_idx(bt, &randval, &bt_idx);
node = malloc(sizeof (int_node_t));
+ ASSERT3P(node, !=, NULL);
+
node->data = randval;
if ((ret = avl_find(&avl, node, &avl_idx)) != NULL) {
- snprintf(why, BUFSIZE, "Found in avl: %llu\n", randval);
+ (void) snprintf(why, BUFSIZE,
+ "Found in avl: %llu\n", randval);
return (1);
}
avl_insert(&avl, node, avl_idx);
@@ -422,7 +427,8 @@ do_negative_test(zfs_btree_t *bt, char *test_name)
{
int rval = 0;
struct rlimit rlim = {0};
- setrlimit(RLIMIT_CORE, &rlim);
+
+ (void) setrlimit(RLIMIT_CORE, &rlim);
if (strcmp(test_name, "insert_duplicate") == 0) {
rval = insert_duplicate(bt);