commit: f7f550ce23ea6c0db4ce33a816aa61e0e815cf91 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> AuthorDate: Wed Jan 22 19:29:30 2020 +0000 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> CommitDate: Wed Jan 22 19:29:30 2020 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=f7f550ce
libq/eat_file: fix Coverity 125891 Ignoring number of bytes read Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> libq/eat_file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libq/eat_file.c b/libq/eat_file.c index 6deabe2..85ba691 100644 --- a/libq/eat_file.c +++ b/libq/eat_file.c @@ -40,7 +40,7 @@ eat_file_fd(int fd, char **bufptr, size_t *bufsize) /* We assume a min allocation size so that repeat calls don't * hit ugly ramp ups -- if you read a file that is 1 byte, then * 5 bytes, then 10 bytes, then 20 bytes, ... you'll allocate - * constantly. So we round up a few pages as wasiting virtual + * constantly. So we round up a few pages as wasting virtual * memory is cheap when it is unused. */ *bufsize = ((read_size + 1) + BUFSIZE - 1) & -BUFSIZE; *bufptr = xrealloc(*bufptr, *bufsize); @@ -55,9 +55,9 @@ eat_file_fd(int fd, char **bufptr, size_t *bufsize) return false; buf[read_size] = '\0'; } else { - if (read(fd, buf, read_size) == 0) + if ((read_size = read(fd, buf, read_size)) <= 0) return false; - buf[read_size - 1] = '\0'; + buf[read_size] = '\0'; } }