diff mbox series

trace-cmd: Silence a logical-not-parentheses warning

Message ID 20210428052540.3364743-1-irogers@google.com (mailing list archive)
State Accepted
Commit 3d389b3b5a266d2771adb3479993d1522e89b650
Headers show
Series trace-cmd: Silence a logical-not-parentheses warning | expand

Commit Message

Ian Rogers April 28, 2021, 5:25 a.m. UTC
Clang 12 generates a warning of:
./tracecmd/trace-stat.c:719:15: error: logical not is only applied to the left hand side of this comparison [-Werror,-Wlogical-not-parentheses]
        if (clock && !strcmp(clock, "local") == 0)
                     ^                       ~~
./tracecmd/trace-stat.c:719:15: note: add parentheses after the '!' to evaluate the comparison first
        if (clock && !strcmp(clock, "local") == 0)
                     ^
                      (                          )
./tracecmd/trace-stat.c:719:15: note: add parentheses around left hand side expression to silence this warning
        if (clock && !strcmp(clock, "local") == 0)
                     ^
                     (                      )

Silence by using "!= 0" as done elsewhere in the code.

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

Comments

Steven Rostedt April 28, 2021, 1:20 p.m. UTC | #1
On Tue, 27 Apr 2021 22:25:40 -0700
Ian Rogers <irogers@google.com> wrote:

> Clang 12 generates a warning of:
> ./tracecmd/trace-stat.c:719:15: error: logical not is only applied to the left hand side of this comparison [-Werror,-Wlogical-not-parentheses]
>         if (clock && !strcmp(clock, "local") == 0)
>                      ^                       ~~
> ./tracecmd/trace-stat.c:719:15: note: add parentheses after the '!' to evaluate the comparison first
>         if (clock && !strcmp(clock, "local") == 0)
>                      ^
>                       (                          )
> ./tracecmd/trace-stat.c:719:15: note: add parentheses around left hand side expression to silence this warning
>         if (clock && !strcmp(clock, "local") == 0)
>                      ^
>                      (                      )
> 
> Silence by using "!= 0" as done elsewhere in the code.

Thanks, this does look like a nice clean up, and not just a removal of a
warning on Clang.

-- Steve


> 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tracecmd/trace-stat.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tracecmd/trace-stat.c b/tracecmd/trace-stat.c
> index 3112787..cb92622 100644
> --- a/tracecmd/trace-stat.c
> +++ b/tracecmd/trace-stat.c
> @@ -716,7 +716,7 @@ static void report_clock(struct buffer_instance *instance)
>  	clock = tracefs_get_clock(tracefs);
>  
>  	/* Default clock is "local", only show others */
> -	if (clock && !strcmp(clock, "local") == 0)
> +	if (clock && strcmp(clock, "local") != 0)
>  		printf("\nClock: %s\n", clock);
>  
>  	free(clock);
diff mbox series

Patch

diff --git a/tracecmd/trace-stat.c b/tracecmd/trace-stat.c
index 3112787..cb92622 100644
--- a/tracecmd/trace-stat.c
+++ b/tracecmd/trace-stat.c
@@ -716,7 +716,7 @@  static void report_clock(struct buffer_instance *instance)
 	clock = tracefs_get_clock(tracefs);
 
 	/* Default clock is "local", only show others */
-	if (clock && !strcmp(clock, "local") == 0)
+	if (clock && strcmp(clock, "local") != 0)
 		printf("\nClock: %s\n", clock);
 
 	free(clock);