Re: [PATCH 3/3] wt-status: use "format" function attribute for status_printf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jeff King <peff@xxxxxxxx> writes:

> 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 <peff@xxxxxxxx>
> ---
> 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.

Yeah, that is a show-stopper for me X-<.

> 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 */
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]