Linux-Trace-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/2] trace-cmd: Add gcc printf format specifier
@ 2021-04-22 21:07 Steven Rostedt
  2021-04-22 21:07 ` [PATCH 1/2] trace-cmd: Add printf format attribute to die() and warning() Steven Rostedt
  2021-04-22 21:07 ` [PATCH 2/2] trace-cmd: Fix up the die() formats Steven Rostedt
  0 siblings, 2 replies; 3+ messages in thread
From: Steven Rostedt @ 2021-04-22 21:07 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Nicolas Sterchele, Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

To keep from having bad warning() or die() formats with repect to their
args, add the gcc printf format specifier that will have gcc check the
formatting of the strings used.

Steven Rostedt (VMware) (2):
  trace-cmd: Add printf format attribute to die() and warning()
  trace-cmd: Fix up the die() formats

 tracecmd/include/trace-local.h |  5 +++++
 tracecmd/trace-dump.c          | 14 +++++++-------
 tracecmd/trace-record.c        |  2 +-
 3 files changed, 13 insertions(+), 8 deletions(-)

-- 
2.29.2


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

* [PATCH 1/2] trace-cmd: Add printf format attribute to die() and warning()
  2021-04-22 21:07 [PATCH 0/2] trace-cmd: Add gcc printf format specifier Steven Rostedt
@ 2021-04-22 21:07 ` Steven Rostedt
  2021-04-22 21:07 ` [PATCH 2/2] trace-cmd: Fix up the die() formats Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2021-04-22 21:07 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Nicolas Sterchele, Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Add the gcc printf format attribute to die(), __die() and warning() such
that any mistake in the formats of the output will be caught by the
compiler.

Link: https://lore.kernel.org/linux-trace-devel/20210422165148.6d0ea90e@gandalf.local.home/

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tracecmd/include/trace-local.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h
index 4235ae21..eadf103e 100644
--- a/tracecmd/include/trace-local.h
+++ b/tracecmd/include/trace-local.h
@@ -27,6 +27,9 @@ typedef unsigned long long u64;
 
 struct buffer_instance;
 
+#define __printf(a, b) __attribute__((format(printf,a,b)))
+
+__printf(1,2)
 void warning(const char *fmt, ...);
 
 /* for local shared information with trace-cmd executable */
@@ -331,8 +334,10 @@ int trace_open_vsock(unsigned int cid, unsigned int port);
 char *trace_get_guest_file(const char *file, const char *guest);
 
 /* No longer in event-utils.h */
+__printf(1,2)
 void __noreturn die(const char *fmt, ...); /* Can be overriden */
 void *malloc_or_die(unsigned int size); /* Can be overridden */
+__printf(1,2)
 void __noreturn __die(const char *fmt, ...);
 void __noreturn _vdie(const char *fmt, va_list ap);
 
-- 
2.29.2


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

* [PATCH 2/2] trace-cmd: Fix up the die() formats
  2021-04-22 21:07 [PATCH 0/2] trace-cmd: Add gcc printf format specifier Steven Rostedt
  2021-04-22 21:07 ` [PATCH 1/2] trace-cmd: Add printf format attribute to die() and warning() Steven Rostedt
@ 2021-04-22 21:07 ` Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2021-04-22 21:07 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Nicolas Sterchele, Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

After adding the printf format attribute to die(), gcc found several
places that the wrong format specifier (or no specifier) was used.

Fix them all up.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tracecmd/trace-dump.c   | 14 +++++++-------
 tracecmd/trace-record.c |  2 +-
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c
index 3f56f65a..98425b98 100644
--- a/tracecmd/trace-dump.c
+++ b/tracecmd/trace-dump.c
@@ -150,13 +150,13 @@ static void dump_initial_format(int fd)
 
 	/* check initial bytes */
 	if (read_file_bytes(fd, buf, sizeof(magic)))
-		die("cannot read %d bytes magic", sizeof(magic));
+		die("cannot read %ld bytes magic", sizeof(magic));
 	if (memcmp(buf, magic, sizeof(magic)) != 0)
 		die("wrong file magic");
 
 	/* check initial tracing string */
 	if (read_file_bytes(fd, buf, strlen(TRACING_STR)))
-		die("cannot read %d bytes tracing string", strlen(TRACING_STR));
+		die("cannot read %ld bytes tracing string", strlen(TRACING_STR));
 	buf[strlen(TRACING_STR)] = 0;
 	if (strncmp(buf, TRACING_STR, strlen(TRACING_STR)) != 0)
 		die("wrong tracing string: %s", buf);
@@ -194,7 +194,7 @@ static void dump_header_page(int fd)
 
 	/* check header string */
 	if (read_file_bytes(fd, buf, strlen(HEAD_PAGE_STR) + 1))
-		die("cannot read %d bytes header string", strlen(HEAD_PAGE_STR));
+		die("cannot read %ld bytes header string", strlen(HEAD_PAGE_STR));
 	if (strncmp(buf, HEAD_PAGE_STR, strlen(HEAD_PAGE_STR)) != 0)
 		die("wrong header string: %s", buf);
 
@@ -215,7 +215,7 @@ static void dump_header_event(int fd)
 
 	/* check header string */
 	if (read_file_bytes(fd, buf, strlen(HEAD_PAGE_EVENT) + 1))
-		die("cannot read %d bytes header string", strlen(HEAD_PAGE_EVENT));
+		die("cannot read %ld bytes header string", strlen(HEAD_PAGE_EVENT));
 	if (strncmp(buf, HEAD_PAGE_EVENT, strlen(HEAD_PAGE_EVENT)) != 0)
 		die("wrong header string: %s", buf);
 
@@ -263,7 +263,7 @@ static void dump_events_format(int fd)
 	while (systems) {
 
 		if (read_file_string(fd, buf, DUMP_SIZE))
-			die("cannot read the name of the $dth system", systems);
+			die("cannot read the name of the %dth system", systems);
 		if (read_file_number(fd, &events, 4))
 			die("cannot read the count of the events in system %s",
 			     buf);
@@ -598,10 +598,10 @@ static void dump_clock(int fd)
 		die("cannot read clock size");
 	clock = calloc(1, size);
 	if (!clock)
-		die("cannot allocate clock %d bytes", size);
+		die("cannot allocate clock %lld bytes", size);
 
 	if (read_file_bytes(fd, clock, size))
-		die("cannot read clock %d bytes", size);
+		die("cannot read clock %lld bytes", size);
 	clock[size] = 0;
 	do_print((SUMMARY | CLOCK), "\t\t%s\n", clock);
 	free(clock);
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index fd03a605..db23c001 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -3838,7 +3838,7 @@ static void setup_guest(struct buffer_instance *instance)
 
 	fd = open(file, O_CREAT|O_WRONLY|O_TRUNC, 0644);
 	if (fd < 0)
-		die("Failed to open", file);
+		die("Failed to open %s", file);
 
 	/* Start reading tracing metadata */
 	if (tracecmd_msg_read_data(msg_handle, fd))
-- 
2.29.2


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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-22 21:07 [PATCH 0/2] trace-cmd: Add gcc printf format specifier Steven Rostedt
2021-04-22 21:07 ` [PATCH 1/2] trace-cmd: Add printf format attribute to die() and warning() Steven Rostedt
2021-04-22 21:07 ` [PATCH 2/2] trace-cmd: Fix up the die() formats Steven Rostedt

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