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