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

Re: [PATCH] fread does not return negative on error

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 23, 2009, 23:56 UTC
Message-ID
<7vhby64i8f.fsf@alter.siamese.dyndns.org>
In-Reply-To
<4A3FB479.2090902@lsrfire.ath.cx>
René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:
> the following patch is for git.  I just removed the unneeded check for
> res == 0 from your version.  Does it look OK?

The patch looks good, and both of our in-tree users do error out when the returned value is 0 (imap-send.c checks with "<= 0" which looks a tad amateurish, though) correctly.

Funny, there is no caller of this function in the original context this bug originally found, which I think is linux-2.6/tools/perf ;-).

Thanks.
Show 23 quoted lines
> From: Roel Kluin <roel.kluin@gmail.com>
>
> size_t res cannot be less than 0. fread returns 0 on error.
>
> Reported-by: Ingo Molnar <mingo@elte.hu>
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
>  strbuf.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/strbuf.c b/strbuf.c
> index a884960..f03d117 100644
> --- a/strbuf.c
> +++ b/strbuf.c
> @@ -260,7 +260,7 @@ size_t strbuf_fread(struct strbuf *sb, size_t size, FILE *f)
>  	res = fread(sb->buf + sb->len, 1, size, f);
>  	if (res > 0)
>  		strbuf_setlen(sb, sb->len + res);
> -	else if (res < 0 && oldalloc == 0)
> +	else if (oldalloc == 0)
>  		strbuf_release(sb);
>  	return res;
>  }
Previous: René ScharfeNext: Ingo Molnar
Message 4 of 14 in “Re: [PATCH] tools: fread does not return negative on error”
  1. Ingo MolnarJun 22, 2009
  2. roel kluinJun 22, 2009
  3. fread does not return negative on errorRené Scharfe, Jun 22, 2009
  4. Junio C HamanoJun 23, 2009
  5. Ingo MolnarJun 24, 2009
  6. Johannes SchindelinJun 24, 2009
  7. Junio C HamanoJun 24, 2009
  8. Johannes SchindelinJun 24, 2009
  9. Ingo MolnarJun 24, 2009
  10. Alex RiesenJun 24, 2009
  11. Junio C HamanoJun 24, 2009
  12. Christian CouderJun 24, 2009
  13. Ingo MolnarJun 24, 2009
  14. Junio C HamanoJun 25, 2009

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.