Skip to content

Commit

Permalink
uftrace: Fix fread() error handling
Browse files Browse the repository at this point in the history
This isn't really accurate right. fread() doesn't always
return 0 in error. It could return < number of elements
and set errno.

Fixed: namhyung#952

Signed-off-by: GwanYeong Kim <[email protected]>
  • Loading branch information
gy741 authored and namhyung committed Oct 18, 2019
1 parent d5ee33c commit 5cffda2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions cmds/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ static int fill_cmdline(void *arg)
struct fill_handler_arg *fha = arg;
char *buf = fha->buf;
FILE *fp;
int ret, i;
size_t ret;
int i;
char *p;

fp = fopen("/proc/self/cmdline", "r");
Expand All @@ -219,7 +220,7 @@ static int fill_cmdline(void *arg)
ret = fread(buf, 1, sizeof(fha->buf), fp);
fclose(fp);

if (ret < 0)
if (ret != sizeof(fha->buf))
return ret;

/* cmdline separated by NUL character - convert to space */
Expand Down
2 changes: 1 addition & 1 deletion utils/symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ int save_kernel_symbol(char *dirname)
while ((len = fread(buf, 1, sizeof(buf), ifp)) > 0)
fwrite(buf, 1, len, ofp);

if (len < 0)
if (len != sizeof(buf))
ret = len;

fclose(ifp);
Expand Down

0 comments on commit 5cffda2

Please sign in to comment.