Linux-Trace-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/3] libtracefs utest: Silence string-plus-int warnings
@ 2021-04-23  3:54 Ian Rogers
  2021-04-23  3:54 ` [PATCH 2/3] libtracefs utest: Fix a sometimes uninitialized variable Ian Rogers
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ian Rogers @ 2021-04-23  3:54 UTC (permalink / raw)
  To: linux-trace-devel, Tzvetomir Stoyanov, Steven Rostedt; +Cc: 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);
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~

Signed-off-by: Ian Rogers <irogers@google.com>
---
 utest/tracefs-utest.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index edb3a3d..c5efd5f 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -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);
-- 
2.31.1.498.g6c1eba8ee3d-goog


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/3] libtracefs utest: Fix a sometimes uninitialized variable.
  2021-04-23  3:54 [PATCH 1/3] libtracefs utest: Silence string-plus-int warnings Ian Rogers
@ 2021-04-23  3:54 ` Ian Rogers
  2021-04-23  3:54 ` [PATCH 3/3] libtracefs utest: Make a null string fatal if it is passed to strstr Ian Rogers
  2021-04-26 11:25 ` [PATCH 1/3] libtracefs utest: Silence string-plus-int warnings Tzvetomir Stoyanov
  2 siblings, 0 replies; 5+ messages in thread
From: Ian Rogers @ 2021-04-23  3:54 UTC (permalink / raw)
  To: linux-trace-devel, Tzvetomir Stoyanov, Steven Rostedt; +Cc: Ian Rogers

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)
                    ^~~~~~~~~~~

Signed-off-by: Ian Rogers <irogers@google.com>
---
 utest/tracefs-utest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index c5efd5f..a0d911b 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -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;
 
-- 
2.31.1.498.g6c1eba8ee3d-goog


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/3] libtracefs utest: Make a null string fatal if it is passed to strstr
  2021-04-23  3:54 [PATCH 1/3] libtracefs utest: Silence string-plus-int warnings Ian Rogers
  2021-04-23  3:54 ` [PATCH 2/3] libtracefs utest: Fix a sometimes uninitialized variable Ian Rogers
@ 2021-04-23  3:54 ` Ian Rogers
  2021-04-26 11:25 ` [PATCH 1/3] libtracefs utest: Silence string-plus-int warnings Tzvetomir Stoyanov
  2 siblings, 0 replies; 5+ messages in thread
From: Ian Rogers @ 2021-04-23  3:54 UTC (permalink / raw)
  To: linux-trace-devel, Tzvetomir Stoyanov, Steven Rostedt; +Cc: Ian Rogers

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@google.com>
---
 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] libtracefs utest: Silence string-plus-int warnings
  2021-04-23  3:54 [PATCH 1/3] libtracefs utest: Silence string-plus-int warnings Ian Rogers
  2021-04-23  3:54 ` [PATCH 2/3] libtracefs utest: Fix a sometimes uninitialized variable Ian Rogers
  2021-04-23  3:54 ` [PATCH 3/3] libtracefs utest: Make a null string fatal if it is passed to strstr Ian Rogers
@ 2021-04-26 11:25 ` Tzvetomir Stoyanov
  2021-04-26 15:16   ` Ian Rogers
  2 siblings, 1 reply; 5+ messages in thread
From: Tzvetomir Stoyanov @ 2021-04-26 11:25 UTC (permalink / raw)
  To: Ian Rogers; +Cc: Linux Trace Devel, Steven Rostedt

On Fri, Apr 23, 2021 at 6:54 AM Ian Rogers <irogers@google.com> wrote:
>
> 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.

Acked-by: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>



> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  utest/tracefs-utest.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
> index edb3a3d..c5efd5f 100644
> --- a/utest/tracefs-utest.c
> +++ b/utest/tracefs-utest.c
> @@ -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);
> --
> 2.31.1.498.g6c1eba8ee3d-goog
>


--
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] libtracefs utest: Silence string-plus-int warnings
  2021-04-26 11:25 ` [PATCH 1/3] libtracefs utest: Silence string-plus-int warnings Tzvetomir Stoyanov
@ 2021-04-26 15:16   ` Ian Rogers
  0 siblings, 0 replies; 5+ messages in thread
From: Ian Rogers @ 2021-04-26 15:16 UTC (permalink / raw)
  To: Tzvetomir Stoyanov; +Cc: Linux Trace Devel, Steven Rostedt

On Mon, Apr 26, 2021 at 4:25 AM Tzvetomir Stoyanov
<tz.stoyanov@gmail.com> wrote:
>
> On Fri, Apr 23, 2021 at 6:54 AM Ian Rogers <irogers@google.com> wrote:
> >
> > 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.

(Re-send with plain-text mode enabled).

Thanks, the compiler is clang 12.

Ian

>
> Acked-by: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
>
>
>
> > Signed-off-by: Ian Rogers <irogers@google.com>
> > ---
> >  utest/tracefs-utest.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
> > index edb3a3d..c5efd5f 100644
> > --- a/utest/tracefs-utest.c
> > +++ b/utest/tracefs-utest.c
> > @@ -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);
> > --
> > 2.31.1.498.g6c1eba8ee3d-goog
> >
>
>
> --
> Tzvetomir (Ceco) Stoyanov
> VMware Open Source Technology Center

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-23  3:54 [PATCH 1/3] libtracefs utest: Silence string-plus-int warnings Ian Rogers
2021-04-23  3:54 ` [PATCH 2/3] libtracefs utest: Fix a sometimes uninitialized variable Ian Rogers
2021-04-23  3:54 ` [PATCH 3/3] libtracefs utest: Make a null string fatal if it is passed to strstr Ian Rogers
2021-04-26 11:25 ` [PATCH 1/3] libtracefs utest: Silence string-plus-int warnings Tzvetomir Stoyanov
2021-04-26 15:16   ` Ian Rogers

Linux-Trace-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-trace-devel/0 linux-trace-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-trace-devel linux-trace-devel/ https://lore.kernel.org/linux-trace-devel \
		linux-trace-devel@vger.kernel.org
	public-inbox-index linux-trace-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-trace-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git