Skip to contentSkip to conversation

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

PATCH In review Ian Rogers 2 participants 2 messages Apr 28, 2021

lore
Share & tools
lore

Ian Rogers

author
#0 lore raw

PATCH 1/1 trace-cmd: Silence a logical-not-parentheses warning

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.

---
 tracecmd/trace-stat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tracecmd/trace-stat.c +1 -1
index 3112787..cb92622 100644
@@ -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);
Signature · 1 line
2.31.1.527.g47e6f16901-goog
#1 lore raw
Quoted 13 lines · On Tue, 27 Apr 2021 22:25:40 -0700 Ian Rogers <[email protected]> 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)
                     ^
                     (                      )
Quoted 1 line

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

Quoted 19 lines
---
 tracecmd/trace-stat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tracecmd/trace-stat.c +1 -1
index 3112787..cb92622 100644
@@ -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);