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

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

From
IMIngo Molnar <mingo@elte.hu>
Date
Jun 22, 2009, 15:34 UTC
Message-ID
<20090622153431.GA18466@elte.hu>
In-Reply-To
<4A3FB09D.9050903@gmail.com>
* Roel Kluin <roel.kluin@gmail.com> wrote:
Show 18 quoted lines
> size_t res cannot be less than 0. fread returns 0 on error.
> 
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
> Is this correct? please review.
> 
> diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c
> index eaba093..376a337 100644
> --- a/tools/perf/util/strbuf.c
> +++ b/tools/perf/util/strbuf.c
> @@ -259,7 +259,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 (res == 0 && oldalloc == 0)
>  		strbuf_release(sb);
>  	return res;
This comes straight from Git's strbuf.c so i've Cc:-ed the Git list.

Roel, did you get some compiler warning that made you look at this code?

	Ingo
Next: roel kluin
Message 1 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.