Skip to contentSkip to conversation

client: apply format attribute to two functions

PATCH In review Rosen Penev 2 participants 4 messages Apr 8, 2020 – Apr 9, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 client: apply format attribute to two functions

Clang was able to find these extra ones.

---
 client/agent.c   | 2 +-
 client/display.h | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)
client/agent.c +1 -1
index b804b50d..157b61c0 100644
@@ -303,7 +303,7 @@ static struct l_dbus_message *request_user_password_method_call(
 
 	username_prompt = l_strdup_printf(COLOR_BLUE PROMPT_USERNAME " "
 						COLOR_OFF "%s\n", username);
-	display(username_prompt);
+	display("%s", username_prompt);
 	l_free(username_prompt);
 
 	display_agent_prompt(PROMPT_PASSWORD, true);
client/display.h +4 -2
index 2b0d8d7c..fbae0c67 100644
@@ -32,8 +32,10 @@ struct command_family;
 #define CLEAR_SCREEN	"\033[2J"
 #define MARGIN		"  "
 
-void display(const char *format, ...);
-void display_table_header(const char *caption, const char *fmt, ...);
+void display(const char *format, ...)
+		__attribute__((format(printf, 1, 2)));
+void display_table_header(const char *caption, const char *fmt, ...)
+		__attribute__((format(printf, 2, 3)));
 void display_table_footer(void);
 void display_error(const char *error);
 void display_command_line(const char *command_family,
Signature · 1 line
2.25.1
#1 lore raw

Hi Rosen,

Quoted 5 lines · Rosen Penev

Clang was able to find these extra ones.

---
  client/agent.c   | 2 +-
  client/display.h | 6 ++++--
  2 files changed, 5 insertions(+), 3 deletions(-)

Looks fine to me, but gcc now complains:

CC client/display.o
client/display.c: In function ‘display_enable_cmd_prompt’:
client/display.c:537:10: error: zero-length gnu_printf format string [-Werror=format-zero-length]
537 | display("");
| ^~

Regards,
-Denis

#2 lore raw
Quoted 10 lines · Denis Kenzior

Hi Rosen,

Quoted 5 lines · Rosen Penev

Clang was able to find these extra ones.

---
  client/agent.c   | 2 +-
  client/display.h | 6 ++++--
  2 files changed, 5 insertions(+), 3 deletions(-)
Quoted 7 lines

Looks fine to me, but gcc now complains:

CC client/display.o
client/display.c: In function ‘display_enable_cmd_prompt’:
client/display.c:537:10: error: zero-length gnu_printf format string [-Werror=format-zero-length]
537 | display("");

What does this do anyway?

Quoted 4 lines

| ^~

Regards,
-Denis

#3 lore raw

Hi Rosen,

Quoted 11 lines · Rosen Penev
Quoted 10 lines · Denis Kenzior

Hi Rosen,

Quoted 5 lines · Rosen Penev

Clang was able to find these extra ones.

---
   client/agent.c   | 2 +-
   client/display.h | 6 ++++--
   2 files changed, 5 insertions(+), 3 deletions(-)
Quoted 8 lines
Quoted 7 lines

Looks fine to me, but gcc now complains:

CC client/display.o
client/display.c: In function ‘display_enable_cmd_prompt’:
client/display.c:537:10: error: zero-length gnu_printf format string [-Werror=format-zero-length]

    537 |  display("");

What does this do anyway?

According to Tim this was needed for some readline behavior. Anyhow, I applied a patch from Tim that gets rid of this particular line.

I went ahead and applied your original patch. Thanks!

Regards,
-Denis