git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] rebase-interactive.c: silence format-zero-length warnings
@ 2020-02-27 20:25 Ralf Thielow via GitGitGadget
  2020-02-27 23:54 ` [PATCH] config.mak.dev: re-enable -Wformat-zero-length Jeff King
  2020-03-03 10:17 ` [PATCH] rebase-interactive.c: silence format-zero-length warnings Alban Gruin
  0 siblings, 2 replies; 6+ messages in thread
From: Ralf Thielow via GitGitGadget @ 2020-02-27 20:25 UTC (permalink / raw)
  To: git; +Cc: Alban Gruin, Ralf Thielow, Ralf Thielow

From: Ralf Thielow <ralf.thielow@gmail.com>

Fixes the following warnings:

rebase-interactive.c: In function ‘edit_todo_list’:
rebase-interactive.c:137:38: warning: zero-length gnu_printf format string [-Wformat-zero-length]
    write_file(rebase_path_dropped(), "");
rebase-interactive.c:144:37: warning: zero-length gnu_printf format string [-Wformat-zero-length]
   write_file(rebase_path_dropped(), "");

Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
---
    rebase-interactive.c: silence format-zero-length warnings
    
    I noticed these warnings a while ago and they're still there, so here's
    my fix.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-567%2Fralfth%2Fformat-zero-length-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-567/ralfth/format-zero-length-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/567

 rebase-interactive.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/rebase-interactive.c b/rebase-interactive.c
index ac001dea588..0a4572e67ea 100644
--- a/rebase-interactive.c
+++ b/rebase-interactive.c
@@ -134,14 +134,14 @@ int edit_todo_list(struct repository *r, struct todo_list *todo_list,
 
 	if (incorrect) {
 		if (todo_list_check_against_backup(r, new_todo)) {
-			write_file(rebase_path_dropped(), "");
+			write_file(rebase_path_dropped(), "%s", "");
 			return -4;
 		}
 
 		if (incorrect > 0)
 			unlink(rebase_path_dropped());
 	} else if (todo_list_check(todo_list, new_todo)) {
-		write_file(rebase_path_dropped(), "");
+		write_file(rebase_path_dropped(), "%s", "");
 		return -4;
 	}
 

base-commit: 2d2118b814c11f509e1aa76cb07110f7231668dc
-- 
gitgitgadget

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

* [PATCH] config.mak.dev: re-enable -Wformat-zero-length
  2020-02-27 20:25 [PATCH] rebase-interactive.c: silence format-zero-length warnings Ralf Thielow via GitGitGadget
@ 2020-02-27 23:54 ` Jeff King
  2020-02-28 16:42   ` Junio C Hamano
  2020-03-03 10:17 ` [PATCH] rebase-interactive.c: silence format-zero-length warnings Alban Gruin
  1 sibling, 1 reply; 6+ messages in thread
From: Jeff King @ 2020-02-27 23:54 UTC (permalink / raw)
  To: Ralf Thielow via GitGitGadget
  Cc: Junio C Hamano, git, Alban Gruin, Ralf Thielow

On Thu, Feb 27, 2020 at 08:25:30PM +0000, Ralf Thielow via GitGitGadget wrote:

> Fixes the following warnings:
> 
> rebase-interactive.c: In function ‘edit_todo_list’:
> rebase-interactive.c:137:38: warning: zero-length gnu_printf format string [-Wformat-zero-length]
>     write_file(rebase_path_dropped(), "");
> rebase-interactive.c:144:37: warning: zero-length gnu_printf format string [-Wformat-zero-length]
>    write_file(rebase_path_dropped(), "");

Thanks, I think this is worth doing.

I had noticed them, too, but then they "went away" so I assumed they had
already been fixed. It turns out that it's the difference between a
build with and without the DEVELOPER Makefile knob set.

I think we should do this on top:

-- >8 --
Subject: [PATCH] config.mak.dev: re-enable -Wformat-zero-length

We recently triggered some -Wformat-zero-length warnings in the code,
but no developers noticed because we suppress that warning in builds
with the DEVELOPER=1 Makefile knob set. But we _don't_ suppress them in
a non-developer build (and they're part of -Wall). So even though
non-developers probably aren't using -Werror, they see the annoying
warnings when they build.

We've had back and forth discussion over the years on whether this
warning is useful or not. In most cases we've seen, it's not true that
the call is a mistake, since we're using its side effects (like adding a
newline status_printf_ln()) or writing an empty string to a destination
which is handled by the function (as in write_file()). And so we end up
working around it in the source by passing ("%s", "").

There's more discussion in the subthread starting at:

  https://lore.kernel.org/git/xmqqtwaod7ly.fsf@gitster.mtv.corp.google.com/

The short of it is that we probably can't just disable the warning for
everybody because of portability issues. And ignoring it for developers
puts us in the situation we're in now, where non-dev builds are annoyed.

Since the workaround is both rarely needed and fairly straight-forward,
let's just commit to doing it as necessary, and re-enable the warning.

Signed-off-by: Jeff King <peff@peff.net>
---
I had totally forgotten about that thread until researching the history
just now. There's another option there involving #pragma, but it was too
gross for me to even suggest now as an alternative in the commit
message. ;) I think this is the most practical improvement.

 config.mak.dev | 1 -
 1 file changed, 1 deletion(-)

diff --git a/config.mak.dev b/config.mak.dev
index bf1f3fcdee..89b218d11a 100644
--- a/config.mak.dev
+++ b/config.mak.dev
@@ -9,7 +9,6 @@ endif
 DEVELOPER_CFLAGS += -Wall
 DEVELOPER_CFLAGS += -Wdeclaration-after-statement
 DEVELOPER_CFLAGS += -Wformat-security
-DEVELOPER_CFLAGS += -Wno-format-zero-length
 DEVELOPER_CFLAGS += -Wold-style-definition
 DEVELOPER_CFLAGS += -Woverflow
 DEVELOPER_CFLAGS += -Wpointer-arith
-- 
2.25.1.911.g022f5304bc


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

* Re: [PATCH] config.mak.dev: re-enable -Wformat-zero-length
  2020-02-27 23:54 ` [PATCH] config.mak.dev: re-enable -Wformat-zero-length Jeff King
@ 2020-02-28 16:42   ` Junio C Hamano
  2020-02-28 17:06     ` Jeff King
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2020-02-28 16:42 UTC (permalink / raw)
  To: Jeff King; +Cc: Ralf Thielow via GitGitGadget, git, Alban Gruin, Ralf Thielow

Jeff King <peff@peff.net> writes:

> The short of it is that we probably can't just disable the warning for
> everybody because of portability issues. And ignoring it for developers
> puts us in the situation we're in now, where non-dev builds are annoyed.

"git blame" unfortunately is very bad at poing at a commit that
removed something, so I do not offhand know how much it would help
readers who later wonder "oh, I am sure we had thing to disable
format-zero-length warning, and I want to learn the reason why we
dropped it", but thanks for writing this down.

> Since the workaround is both rarely needed and fairly straight-forward,
> let's just commit to doing it as necessary, and re-enable the warning.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> I had totally forgotten about that thread until researching the history
> just now. There's another option there involving #pragma, but it was too
> gross for me to even suggest now as an alternative in the commit
> message. ;) I think this is the most practical improvement.
>
>  config.mak.dev | 1 -
>  1 file changed, 1 deletion(-)
>
> diff --git a/config.mak.dev b/config.mak.dev
> index bf1f3fcdee..89b218d11a 100644
> --- a/config.mak.dev
> +++ b/config.mak.dev
> @@ -9,7 +9,6 @@ endif
>  DEVELOPER_CFLAGS += -Wall
>  DEVELOPER_CFLAGS += -Wdeclaration-after-statement
>  DEVELOPER_CFLAGS += -Wformat-security
> -DEVELOPER_CFLAGS += -Wno-format-zero-length
>  DEVELOPER_CFLAGS += -Wold-style-definition
>  DEVELOPER_CFLAGS += -Woverflow
>  DEVELOPER_CFLAGS += -Wpointer-arith

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

* Re: [PATCH] config.mak.dev: re-enable -Wformat-zero-length
  2020-02-28 16:42   ` Junio C Hamano
@ 2020-02-28 17:06     ` Jeff King
  0 siblings, 0 replies; 6+ messages in thread
From: Jeff King @ 2020-02-28 17:06 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Ralf Thielow via GitGitGadget, git, Alban Gruin, Ralf Thielow

On Fri, Feb 28, 2020 at 08:42:47AM -0800, Junio C Hamano wrote:

> Jeff King <peff@peff.net> writes:
> 
> > The short of it is that we probably can't just disable the warning for
> > everybody because of portability issues. And ignoring it for developers
> > puts us in the situation we're in now, where non-dev builds are annoyed.
> 
> "git blame" unfortunately is very bad at poing at a commit that
> removed something, so I do not offhand know how much it would help
> readers who later wonder "oh, I am sure we had thing to disable
> format-zero-length warning, and I want to learn the reason why we
> dropped it", but thanks for writing this down.

I often turn to "git log -Sformat-zero" for this (and in fact that was
very useful for the research I did yesterday). But of course you have to
first _know_ about the warning and wonder "hey, didn't used ignore it?"
for that to be useful.

-Peff

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

* Re: [PATCH] rebase-interactive.c: silence format-zero-length warnings
  2020-02-27 20:25 [PATCH] rebase-interactive.c: silence format-zero-length warnings Ralf Thielow via GitGitGadget
  2020-02-27 23:54 ` [PATCH] config.mak.dev: re-enable -Wformat-zero-length Jeff King
@ 2020-03-03 10:17 ` Alban Gruin
  2020-03-03 14:20   ` Junio C Hamano
  1 sibling, 1 reply; 6+ messages in thread
From: Alban Gruin @ 2020-03-03 10:17 UTC (permalink / raw)
  To: Ralf Thielow via GitGitGadget, git
  Cc: Ralf Thielow, Jeff King, Junio C Hamano

Hi Ralf,

Le 27/02/2020 à 21:25, Ralf Thielow via GitGitGadget a écrit :
> From: Ralf Thielow <ralf.thielow@gmail.com>
> 
> Fixes the following warnings:
> 
> rebase-interactive.c: In function ‘edit_todo_list’:
> rebase-interactive.c:137:38: warning: zero-length gnu_printf format string [-Wformat-zero-length]
>     write_file(rebase_path_dropped(), "");
> rebase-interactive.c:144:37: warning: zero-length gnu_printf format string [-Wformat-zero-length]
>    write_file(rebase_path_dropped(), "");
> 
> Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
> ---
>     rebase-interactive.c: silence format-zero-length warnings
>     
>     I noticed these warnings a while ago and they're still there, so here's
>     my fix.
> 
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-567%2Fralfth%2Fformat-zero-length-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-567/ralfth/format-zero-length-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/567
> 
>  rebase-interactive.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/rebase-interactive.c b/rebase-interactive.c
> index ac001dea588..0a4572e67ea 100644
> --- a/rebase-interactive.c
> +++ b/rebase-interactive.c
> @@ -134,14 +134,14 @@ int edit_todo_list(struct repository *r, struct todo_list *todo_list,
>  
>  	if (incorrect) {
>  		if (todo_list_check_against_backup(r, new_todo)) {
> -			write_file(rebase_path_dropped(), "");
> +			write_file(rebase_path_dropped(), "%s", "");
>  			return -4;
>  		}
>  
>  		if (incorrect > 0)
>  			unlink(rebase_path_dropped());
>  	} else if (todo_list_check(todo_list, new_todo)) {
> -		write_file(rebase_path_dropped(), "");
> +		write_file(rebase_path_dropped(), "%s", "");
>  		return -4;
>  	}
>  
> 
> base-commit: 2d2118b814c11f509e1aa76cb07110f7231668dc
> 

Ack.

On a tangent: what's wrong with empty format strings?

Cheers,
Alban


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

* Re: [PATCH] rebase-interactive.c: silence format-zero-length warnings
  2020-03-03 10:17 ` [PATCH] rebase-interactive.c: silence format-zero-length warnings Alban Gruin
@ 2020-03-03 14:20   ` Junio C Hamano
  0 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2020-03-03 14:20 UTC (permalink / raw)
  To: Alban Gruin; +Cc: Ralf Thielow via GitGitGadget, git, Ralf Thielow, Jeff King

Alban Gruin <alban.gruin@gmail.com> writes:

>> Fixes the following warnings:
>> 
>> rebase-interactive.c: In function ‘edit_todo_list’:
>> rebase-interactive.c:137:38: warning: zero-length gnu_printf format string [-Wformat-zero-length]
>>     write_file(rebase_path_dropped(), "");
>> rebase-interactive.c:144:37: warning: zero-length gnu_printf format string [-Wformat-zero-length]
> ...
> On a tangent: what's wrong with empty format strings?

Those functions that are truly printf-like, such a call would be
no-op and an indication of possible typo ("did you forget a %s or
something?"), I presume.

But many of our functions that take printf-like format strings will
do useful things even when an empty string is given, so the warning
is unwanted.

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

end of thread, other threads:[~2020-03-03 14:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-27 20:25 [PATCH] rebase-interactive.c: silence format-zero-length warnings Ralf Thielow via GitGitGadget
2020-02-27 23:54 ` [PATCH] config.mak.dev: re-enable -Wformat-zero-length Jeff King
2020-02-28 16:42   ` Junio C Hamano
2020-02-28 17:06     ` Jeff King
2020-03-03 10:17 ` [PATCH] rebase-interactive.c: silence format-zero-length warnings Alban Gruin
2020-03-03 14:20   ` Junio C Hamano

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

	https://80x24.org/mirrors/git.git

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).