git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: cat-file timing window on Cygwin

From
Jeff King <peff@peff.net>
Date
Aug 26, 2017, 18:53 UTC
Message-ID
<20170826185337.hrcswjuunon54kgj@sigill.intra.peff.net>
In-Reply-To
<253bf111-4e8a-54b7-6e39-2908270aa357@ramsayjones.plus.com>
On Sat, Aug 26, 2017 at 01:57:18AM +0100, Ramsay Jones wrote:
Show 16 quoted lines
> > diff --git a/run-command.c b/run-command.c
> > index 98621faca8..064ebd1995 100644
> > --- a/run-command.c
> > +++ b/run-command.c
> > @@ -641,7 +641,6 @@ int start_command(struct child_process *cmd)
> >  	}
> >  
> >  	trace_argv_printf(cmd->argv, "trace: run_command:");
> > -	fflush(NULL);
> >  
> >  #ifndef GIT_WINDOWS_NATIVE
> >  {
> 
> I suspect not, but I can give it a try ...
> 
> ... oh, wow, that works! Ahem. (Hmm, so it's flushing stdin?!)

Interesting. I find it a little hard to believe there's so obvious a bug as "fflush(NULL) flushes stdin", but well...that's what it seems like.

If that's truly what it is, this is the minimal reproduction I came up with:

-- >8 -- #include <stdio.h>

int main(void)
{
	char buf[256];
	while (fgets(buf, sizeof(buf), stdin)) {
		fprintf(stdout, "got: %s", buf);
		fflush(NULL);
	}
	return 0;
}
-- 8< --

If this really is the bug, then doing something like "seq 10 | ./a.out" would drop some of the input lines.

-Peff
Previous: Adam DinwoodieNext: Adam Dinwoodie
Message 5 of 11 in “cat-file timing window on Cygwin”
  1. Adam DinwoodieAug 25, 2017
  2. Jeff KingAug 25, 2017
  3. Ramsay JonesAug 26, 2017
  4. Adam DinwoodieAug 26, 2017
  5. Jeff KingAug 26, 2017
  6. Adam DinwoodieAug 26, 2017
  7. Ramsay JonesAug 27, 2017
  8. Adam DinwoodieAug 27, 2017
  9. Ramsay JonesAug 27, 2017
  10. Jason PyeronAug 27, 2017
  11. Ramsay JonesSep 8, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.