Blame SOURCES/0246-coverity-Check-return-value-of-fstat-call-def31.patch

4b6aa8
From 29f2027d3ac1cc26d1e21fb91bcc0714d1bec12a Mon Sep 17 00:00:00 2001
4b6aa8
From: Martin Kutlak <mkutlak@redhat.com>
4b6aa8
Date: Mon, 20 Aug 2018 15:08:33 +0000
4b6aa8
Subject: [PATCH] coverity: Check return value of fstat call #def31
4b6aa8
4b6aa8
Signed-off-by: Martin Kutlak <mkutlak@redhat.com>
4b6aa8
4b6aa8
4b6aa8
(cherry picked from commit 78e0ba4ce8d2e31c67e026f32279ad9f46a387f5)
4b6aa8
---
4b6aa8
 src/lib/read_write.c | 4 ++--
4b6aa8
 1 file changed, 2 insertions(+), 2 deletions(-)
4b6aa8
4b6aa8
diff --git a/src/lib/read_write.c b/src/lib/read_write.c
4b6aa8
index 7ce2097..bd8bbe8 100644
4b6aa8
--- a/src/lib/read_write.c
4b6aa8
+++ b/src/lib/read_write.c
4b6aa8
@@ -133,8 +133,8 @@ void* xmalloc_read(int fd, size_t *maxsz_p)
4b6aa8
     /* Estimate file size */
4b6aa8
     {
4b6aa8
         struct stat st;
4b6aa8
-        st.st_size = 0; /* in case fstat fails, assume 0 */
4b6aa8
-        fstat(fd, &st);
4b6aa8
+        if (fstat(fd, &st) != 0)
4b6aa8
+            st.st_size = 0; /* in case fstat fails, assume 0 */
4b6aa8
         /* /proc/N/stat files report st_size 0 */
4b6aa8
         /* In order to make such files readable, we add small const (4k) */
4b6aa8
         size = (st.st_size | 0xfff) + 1;
4b6aa8
-- 
4b6aa8
2.21.0
4b6aa8