trace-cmd: Fix warnings reported by gcc 8.2
PATCH 1/1 trace-cmd: Fix warnings reported by gcc 8.2
From: Slavomir Kaslev <[email protected]>
Compiling trace-cmd with gcc 8.2 reports:
str_error_r.c: In function ‘str_error_r’:
str_error_r.c:24:3: warning: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Wrestrict]
snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err); ^~~~~~~~
since snprintf declares its first argument as __restrict but buf is also passed as argument #5.
--- lib/traceevent/str_error_r.c | 2 +- tracecmd/trace-read.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
lib/traceevent/str_error_r.c +1 -1
@@ -21,6 +21,6 @@ char *str_error_r(int errnum, char *buf, size_t buflen) {int err =strerror_r (errnum, buf, buflen);if (err) -snprintf (buf, buflen,"INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d" , errnum, buf, buflen, err); +snprintf (buf, buflen,"INTERNAL ERROR: strerror_r(%d)=%d" , errnum, err);return buf; }
tracecmd/trace-read.c +4 -4
@@ -386,7 +386,7 @@ static void add_pid_filter(const char *arg)static char *append_pid_filter (char *curr_filter,char *pid) {char *filter; -int len; +int len, curr_len;#define FILTER_FMT "(common_pid==" __STR ")||(pid==" __STR ")||(next_pid==" __STR ")"
@@ -405,13 +405,13 @@ static char *append_pid_filter(char *curr_filter, char *pid)die ("Failed to allocate for filter %s" , curr_filter);sprintf (filter,".*:" FILTER_FMT , pid, pid, pid); }else { - - len +=strlen (curr_filter); + curr_len =strlen (curr_filter); + len += curr_len; filter =realloc (curr_filter, len);if (!filter)die ("realloc" ); -sprintf (filter,"%s||" FILTER_FMT , filter, pid, pid, pid); +sprintf (filter + curr_len,"||" FILTER_FMT , pid, pid, pid); }return filter;
Signature · 1 line
2.19.1
Ping.
Quoted 64 lines · On Wed, Nov 14, 2018 at 5:43 PM <[email protected]> wrote:
From: Slavomir Kaslev <[email protected]>
Compiling trace-cmd with gcc 8.2 reports:
str_error_r.c: In function ‘str_error_r’:
str_error_r.c:24:3: warning: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Wrestrict]
snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err); ^~~~~~~~since
snprintfdeclares its first argument as__restrictbutbufis also passed as argument #5.Signed-off-by Slavomir Kaslev <[email protected]>--- lib/traceevent/str_error_r.c | 2 +- tracecmd/trace-read.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)lib/traceevent/str_error_r.c +1
-1@@ -21,6 +21,6 @@ char *str_error_r(int errnum, char *buf, size_t buflen) {int err =strerror_r (errnum, buf, buflen);if (err) -snprintf (buf, buflen,"INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d" , errnum, buf, buflen, err); +snprintf (buf, buflen,"INTERNAL ERROR: strerror_r(%d)=%d" , errnum, err);return buf; }tracecmd/trace-read.c +4
-5@@ -386,7 +386,7 @@ static void add_pid_filter(const char *arg)static char *append_pid_filter (char *curr_filter,char *pid) {char *filter; -int len; +int len, curr_len;#define FILTER_FMT "(common_pid==" __STR ")||(pid==" __STR ")||(next_pid==" __STR ")"@@ -405,13 +405,13 @@ static char *append_pid_filter(char *curr_filter, char *pid)die ("Failed to allocate for filter %s" , curr_filter);sprintf (filter,".*:" FILTER_FMT , pid, pid, pid); }else { - - len +=strlen (curr_filter); + curr_len =strlen (curr_filter); + len += curr_len; filter =realloc (curr_filter, len);if (!filter)die ("realloc" ); -sprintf (filter,"%s||" FILTER_FMT , filter, pid, pid, pid); +sprintf (filter + curr_len,"||" FILTER_FMT , pid, pid, pid); }return filter; --2.19.1
Quoted 1 line · On Tue, 27 Nov 2018 10:43:17 +0000 Slavomir Kaslev <[email protected]> wrote:
Ping.
Thanks for the reminder.
Quoted 6 lines · On Wed, Nov 14, 2018 at 5:43 PM <[email protected]> wrote:
Quoted 5 lines
From: Slavomir Kaslev <[email protected]>
Compiling trace-cmd with gcc 8.2 reports:
Quoted 7 lines
Quoted 7 lines
str_error_r.c: In function ‘str_error_r’:
str_error_r.c:24:3: warning: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Wrestrict]
snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err); ^~~~~~~~since
snprintfdeclares its first argument as__restrictbutbufis also passed as argument #5.
Ah, this is fixed in the Linux kernel tree.
Tzvetomir, can you back port commit 854e55ad289 ("objtool, perf: Fix GCC 8 -Wrestrict error") from Linux to trace-cmd?
Thanks!
-- Steve
Quoted 52 lines
Quoted 52 lines
Signed-off-by Slavomir Kaslev <[email protected]>--- lib/traceevent/str_error_r.c | 2 +- tracecmd/trace-read.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)lib/traceevent/str_error_r.c +1
-1@@ -21,6 +21,6 @@ char *str_error_r(int errnum, char *buf, size_t buflen) {int err =strerror_r (errnum, buf, buflen);if (err) -snprintf (buf, buflen,"INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d" , errnum, buf, buflen, err); +snprintf (buf, buflen,"INTERNAL ERROR: strerror_r(%d)=%d" , errnum, err);return buf; }tracecmd/trace-read.c +4
-5@@ -386,7 +386,7 @@ static void add_pid_filter(const char *arg)static char *append_pid_filter (char *curr_filter,char *pid) {char *filter; -int len; +int len, curr_len;#define FILTER_FMT "(common_pid==" __STR ")||(pid==" __STR ")||(next_pid==" __STR ")"@@ -405,13 +405,13 @@ static char *append_pid_filter(char *curr_filter, char *pid)die ("Failed to allocate for filter %s" , curr_filter);sprintf (filter,".*:" FILTER_FMT , pid, pid, pid); }else { - - len +=strlen (curr_filter); + curr_len =strlen (curr_filter); + len += curr_len; filter =realloc (curr_filter, len);if (!filter)die ("realloc" ); -sprintf (filter,"%s||" FILTER_FMT , filter, pid, pid, pid); +sprintf (filter + curr_len,"||" FILTER_FMT , pid, pid, pid); }return filter; --2.19.1