Fix creating file buffer in case of file size is zero 09/164909/2
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Thu, 21 Dec 2017 06:18:33 +0000 (09:18 +0300)
committerDmitry Kovalenko <d.kovalenko@samsung.com>
Wed, 10 Jan 2018 12:43:06 +0000 (12:43 +0000)
Change-Id: I9cc666191742d041b330e3f9a0b00d743b8f1b92
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
helper/file_buffer.c

index d6f0ea715a6f754b08e3f72ef242fc2872f55655..a7c0ac3d6e7ba3e846a9834bb22dc06827692e5f 100644 (file)
 #include "daprobe.h"
 
 
-static size_t fsize(int fd)
+static ssize_t fsize(int fd)
 {
        struct stat st;
        if (fstat(fd, &st) != 0)
-               return 0;
+               return -1;
        return st.st_size;
 }
 
@@ -65,6 +65,7 @@ static int do_read_file(int fd, void *data, size_t len)
 struct file_buffer *file_buffer_create(const char *path)
 {
        int fd, ret;
+       ssize_t size;
        struct file_buffer *fb;
        const size_t MAX_FILE_SIZE = 32 * 1024 * 1024;
 
@@ -80,12 +81,13 @@ struct file_buffer *file_buffer_create(const char *path)
                goto free_fb;
        }
 
-       fb->size = fsize(fd);
-       if (!fb->size) {
+       size = fsize(fd);
+       if (size < 0) {
                PRINTERR("Cannot calculate file size, path='%s'", path);
                goto close_fd;
        }
 
+       fb->size = size;
        if (fb->size > MAX_FILE_SIZE) {
                PRINTERR("File size is very long, size=%zu", fb->size);
                goto close_fd;