lkml.org 
[lkml]   [2009]   [Jun]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] tools: fread does not return negative on error

* Roel Kluin <roel.kluin@gmail.com> wrote:

> 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


\
 
 \ /
  Last update: 2009-06-22 17:37    [W:0.053 / U:1.932 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site