[PATCH 3/3] libtracefs utest: Make a null string fatal if it is passed to strstr

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

 



strstr will segv for a null string. If a string is passed to strstr and
is null there is no point segving, it is better to fail the earlier test
with a fatal and continue the rest of the suite. This allows the suite
to complete with an error rather than die.

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
 utest/tracefs-utest.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index a0d911b..e846dc4 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -452,21 +452,21 @@ static void test_instance_file(void)
 	ret = tracefs_instance_file_write(NULL, KPROB_EVTS, KPROBE_1);
 	CU_TEST(ret == strlen(KPROBE_1));
 	kprobes = tracefs_instance_file_read(NULL, KPROB_EVTS, &size);
-	CU_TEST(kprobes != NULL);
+	CU_TEST_FATAL(kprobes != NULL);
 	CU_TEST(strstr(kprobes, &KPROBE_1[2]) != NULL);
 	free(kprobes);
 
 	ret = tracefs_instance_file_append(NULL, KPROB_EVTS, KPROBE_2);
 	CU_TEST(ret == strlen(KPROBE_2));
 	kprobes = tracefs_instance_file_read(NULL, KPROB_EVTS, &size);
-	CU_TEST(kprobes != NULL);
+	CU_TEST_FATAL(kprobes != NULL);
 	CU_TEST(strstr(kprobes, &KPROBE_2[2]) != NULL);
 	free(kprobes);
 
 	ret = tracefs_instance_file_append(NULL, KPROB_EVTS, KPROBE_1_RM);
 	CU_TEST(ret == strlen(KPROBE_1_RM));
 	kprobes = tracefs_instance_file_read(NULL, KPROB_EVTS, &size);
-	CU_TEST(kprobes != NULL);
+	CU_TEST_FATAL(kprobes != NULL);
 	CU_TEST(strstr(kprobes, &KPROBE_1[2]) == NULL);
 	free(kprobes);
 
@@ -1026,7 +1026,7 @@ static void current_clock_check(struct tracefs_instance *instance, const char *c
 	char *str;
 
 	clocks = tracefs_instance_file_read(instance, TRACE_CLOCK, &size);
-	CU_TEST(clocks != NULL);
+	CU_TEST_FATAL(clocks != NULL);
 	CU_TEST(size > strlen(clock));
 	str = strstr(clocks, clock);
 	CU_TEST(str != NULL);
@@ -1041,7 +1041,7 @@ static void test_instance_get_clock(struct tracefs_instance *instance)
 	const char *clock;
 
 	clock = tracefs_get_clock(instance);
-	CU_TEST(clock != NULL);
+	CU_TEST_FATAL(clock != NULL);
 	current_clock_check(instance, clock);
 	free((char *)clock);
 }
-- 
2.31.1.498.g6c1eba8ee3d-goog




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux