libtracefs utest: Silence string-plus-int warnings
PATCH 1/3 libtracefs utest: Silence string-plus-int warnings
Fix warnings of the form:
utest/tracefs-utest.c:476:35: error: adding 'int' to a string does not append to the string [-Werror,-Wstring-plus-int]
CU_TEST(strstr(kprobes, KPROBE_1 + 2) != NULL);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~--- utest/tracefs-utest.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
utest/tracefs-utest.c +3 -3
@@ -453,21 +453,21 @@ static void test_instance_file(void)CU_TEST (ret ==strlen (KPROBE_1 )); kprobes =tracefs_instance_file_read (NULL ,KPROB_EVTS , &size);CU_TEST (kprobes !=NULL ); -CU_TEST (strstr (kprobes,KPROBE_1 +2 ) !=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 (strstr (kprobes,KPROBE_2 +2 ) !=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 (strstr (kprobes,KPROBE_1 +2 ) ==NULL ); +CU_TEST (strstr (kprobes, &KPROBE_1 [2 ]) ==NULL );free (kprobes); ret =tracefs_instance_file_clear (NULL ,KPROB_EVTS );
Signature · 1 line
2.31.1.498.g6c1eba8ee3d-goog
PATCH 2/3 libtracefs utest: Fix a sometimes uninitialized variable.
The warning looks like:
utest/tracefs-utest.c:706:7: error: variable 'fd' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
if (rstat != -1)
^~~~~~~~~~~--- utest/tracefs-utest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
utest/tracefs-utest.c +1 -1
@@ -659,7 +659,7 @@ static bool check_option(struct tracefs_instance *instance,bool supported;struct stat st;char buf[10 ]; -int fd; +int fd =0 ;int r;int rstat;
Signature · 1 line
2.31.1.498.g6c1eba8ee3d-goog
PATCH 3/3 libtracefs utest: Make a null string fatal if it is passed to strstr
In reply to Ian Rogersstrstr 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.
--- utest/tracefs-utest.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
utest/tracefs-utest.c +5 -5
@@ -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 *cchar *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); }
Signature · 1 line
2.31.1.498.g6c1eba8ee3d-goog
Quoted 7 lines · Ian Rogers
Fix warnings of the form:
utest/tracefs-utest.c:476:35: error: adding 'int' to a string does not append to the string [-Werror,-Wstring-plus-int]CU_TEST(strstr(kprobes, KPROBE_1 + 2) != NULL); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
Hi Ian,
Thanks for testing and sending this patch. What compiler/version/options you are using to get these warnings ? The whole patchset looks good to me.
Quoted 35 lines
Signed-off-by Ian Rogers <[email protected]>--- utest/tracefs-utest.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)utest/tracefs-utest.c +3
-4@@ -453,21 +453,21 @@ static void test_instance_file(void)CU_TEST (ret ==strlen (KPROBE_1 )); kprobes =tracefs_instance_file_read (NULL ,KPROB_EVTS , &size);CU_TEST (kprobes !=NULL ); -CU_TEST (strstr (kprobes,KPROBE_1 +2 ) !=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 (strstr (kprobes,KPROBE_2 +2 ) !=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 (strstr (kprobes,KPROBE_1 +2 ) ==NULL ); +CU_TEST (strstr (kprobes, &KPROBE_1 [2 ]) ==NULL );free (kprobes); ret =tracefs_instance_file_clear (NULL ,KPROB_EVTS ); --
Quoted 2 lines
2.31.1.498.g6c1eba8ee3d-goog
--
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center
Quoted 10 lines · Tzvetomir Stoyanov
Quoted 7 lines · Ian Rogers
Fix warnings of the form:
utest/tracefs-utest.c:476:35: error: adding 'int' to a string does not append to the string [-Werror,-Wstring-plus-int]CU_TEST(strstr(kprobes, KPROBE_1 + 2) != NULL); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
Quoted 4 lines
Hi Ian,
Thanks for testing and sending this patch. What compiler/version/options you are using to get these warnings ? The whole patchset looks good to me.
(Re-send with plain-text mode enabled).
Thanks, the compiler is clang 12.
Ian
Quoted 47 lines
Quoted 35 lines
Signed-off-by Ian Rogers <[email protected]>--- utest/tracefs-utest.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)utest/tracefs-utest.c +3
-4@@ -453,21 +453,21 @@ static void test_instance_file(void)CU_TEST (ret ==strlen (KPROBE_1 )); kprobes =tracefs_instance_file_read (NULL ,KPROB_EVTS , &size);CU_TEST (kprobes !=NULL ); -CU_TEST (strstr (kprobes,KPROBE_1 +2 ) !=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 (strstr (kprobes,KPROBE_2 +2 ) !=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 (strstr (kprobes,KPROBE_1 +2 ) ==NULL ); +CU_TEST (strstr (kprobes, &KPROBE_1 [2 ]) ==NULL );free (kprobes); ret =tracefs_instance_file_clear (NULL ,KPROB_EVTS ); --Quoted 2 lines
2.31.1.498.g6c1eba8ee3d-goog
--
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center