list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <>
To: Matt Kraai <>
Cc: Junio C Hamano <>,
Subject: [PATCH 3/3] wt-status: use "format" function attribute for status_printf
Date: Tue, 9 Jul 2013 20:23:28 -0400	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

These functions could benefit from the added compile-time
safety of having the compiler check printf arguments.

Unfortunately, we also sometimes pass an empty format string,
which will cause false positives with -Wformat-zero-length.
In this case, that warning is wrong because our function is
not a no-op with an empty format: it may be printing
colorized output along with a trailing newline.

Signed-off-by: Jeff King <>
I'm torn on this one. It really does provide us with more compile-time
safety checks, but it's annoying that "-Wall -Werror" will no longer
work out of the box.

We could also add a status_printf_empty_line() function, but that feels
like a bit of a hack. Searching online, I also found the amusing
suggestion to do:

  status_printf_ln(s, color, "%.*s", 0,
                   "-Wformat-zero-length please choke on a bucket of socks");

but I think that is probably worse than adding a specialized function.

 wt-status.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/wt-status.h b/wt-status.h
index 4121bc2..fb7152e 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -96,9 +96,9 @@ void wt_porcelain_print(struct wt_status *s);
 void wt_shortstatus_print(struct wt_status *s);
 void wt_porcelain_print(struct wt_status *s);
-void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, ...)
-	;
-void status_printf(struct wt_status *s, const char *color, const char *fmt, ...)
-	;
+__attribute__((format (printf, 3, 4)))
+void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, ...);
+__attribute__((format (printf, 3, 4)))
+void status_printf(struct wt_status *s, const char *color, const char *fmt, ...);
 #endif /* STATUS_H */

  parent reply	other threads:[~2013-07-10  0:23 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-09  5:18 [PATCH] remote-http: use argv-array Junio C Hamano
2013-07-09  6:05 ` Bert Wesarg
2013-07-09  6:38   ` Jeff King
2013-07-09 22:27     ` Matt Kraai
2013-07-10  0:16       ` Jeff King
2013-07-10  0:18         ` [PATCH 1/3] add missing "format" function attributes Jeff King
2013-07-10  0:19         ` [PATCH 2/3] use "sentinel" function attribute for variadic lists Jeff King
2013-07-10  0:23         ` Jeff King [this message]
2013-07-10  5:26           ` [PATCH 3/3] wt-status: use "format" function attribute for status_printf Junio C Hamano
2013-07-10  5:28             ` Jeff King
2013-07-10  5:35               ` Junio C Hamano
2013-07-10  5:40                 ` Jeff King
2013-07-10  5:52                   ` Junio C Hamano
2013-07-10  6:11                     ` Jeff King
2013-07-10  6:17                       ` Junio C Hamano
2013-07-12 16:10               ` Junio C Hamano
2013-07-12 20:44                 ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \
    --subject='Re: [PATCH 3/3] wt-status: use "format" function attribute for status_printf' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).