[PATCH 7/8] Fix -Wformat-nonliteral and -Wformat warnings with clang

Tom Stellard tstellar@redhat.com
Mon Nov 30 19:58:40 GMT 2020


---
 stapbpf/stapbpf.cxx | 4 ++--
 staprun/common.c    | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/stapbpf/stapbpf.cxx b/stapbpf/stapbpf.cxx
index 933164851..7b614015a 100644
--- a/stapbpf/stapbpf.cxx
+++ b/stapbpf/stapbpf.cxx
@@ -246,7 +246,7 @@ static std::vector<uprobe_data> uprobes;
 
 // TODO: Move fatal() to bpfinterp.h and replace abort() calls in the interpreter.
 // TODO: Add warn() option.
-static void __attribute__((noreturn))
+static void __attribute__((noreturn))  __attribute__ ((format (printf, 1, 2)))
 fatal(const char *str, ...)
 {
   if (module_name)
@@ -773,7 +773,7 @@ kprobe_collect_from_syms(Elf_Data *sym_data, Elf_Data *str_data)
       if (syms[i].st_name < str_data->d_size)
 	name = static_cast<char *>(str_data->d_buf) + syms[i].st_name;
       else
-	fatal("symbol %u has invalid string index\n", i);
+	fatal("symbol %zu has invalid string index\n", i);
       maybe_collect_kprobe(name, i, syms[i].st_shndx, syms[i].st_value);
     }
 }
diff --git a/staprun/common.c b/staprun/common.c
index 6a603cd2b..6f1b3d683 100644
--- a/staprun/common.c
+++ b/staprun/common.c
@@ -683,6 +683,7 @@ int send_request(int type, void *data, int len)
 
 static int use_syslog = 0;
 
+ __attribute__ ((format (printf, 1, 2)))
 void eprintf(const char *fmt, ...)
 {
 	va_list va;
@@ -712,7 +713,7 @@ void print_color(const char *type)
 		char *seq = parse_stap_color(type);
 		if (seq != NULL) {
 			eprintf("\033[");
-			eprintf(seq);
+			eprintf("%s", seq);
 			eprintf("m\033[K");
 			free(seq);
 		}
-- 
2.26.2



More information about the Systemtap mailing list