coverity: Fix coverity issue 62/226162/2 accepted/tizen/unified/20200228.123730 submit/tizen/20200227.094013
authorsanghyeok.oh <sanghyeok.oh@samsung.com>
Thu, 27 Feb 2020 07:37:15 +0000 (16:37 +0900)
committersanghyeok.oh <sanghyeok.oh@samsung.com>
Thu, 27 Feb 2020 08:41:08 +0000 (17:41 +0900)
Coverity: #1124568, #1044318

Change-Id: I87b998521582b7562ac4e056332301cdb7697e54

src/libdlogutil/fdi_logger.c
src/libdlogutil/logretrieve.c
tests/test_filters.c

index 73cab62..b31ee75 100644 (file)
@@ -149,6 +149,7 @@ static int logger_create(struct fd_info *fdi, const struct log_config *conf, con
 
        int ret = 0;
        int const PATH_SIZE = MAX_CONF_VAL_LEN;
+       int opened = 0;
 
        char *const actual_path = malloc(PATH_SIZE);
        struct logger_priv_data *const lpd = malloc(sizeof *lpd);
@@ -157,7 +158,7 @@ static int logger_create(struct fd_info *fdi, const struct log_config *conf, con
                goto failure;
        }
 
-       int opened = logger_open_buffer_from_config_get_path(log_id_by_name(name), conf, O_RDWR, &fdi->fd, actual_path, PATH_SIZE);
+       opened = logger_open_buffer_from_config_get_path(log_id_by_name(name), conf, O_RDWR, &fdi->fd, actual_path, PATH_SIZE);
        if (opened <= 0) {
                ret = opened ?: -EINVAL;
                goto failure;
index a555623..a19d79d 100644 (file)
@@ -10,18 +10,22 @@ int create_initial_fdis(struct fd_info ***fdis, int enabled_buffers, bool is_pip
        assert(fdis);
        assert(conf);
 
+       int ret;
+       struct fd_info **fdi_ptrs;
+       unsigned int mask;
+       int fdi_cnt = 0;
+       int r;
+
        if (enabled_buffers == 0)
                return TIZEN_ERROR_INVALID_PARAMETER;
 
-       int ret;
-
-       struct fd_info **fdi_ptrs = calloc(bit_count(enabled_buffers) + 1 /* NULL terminator */, sizeof *fdi_ptrs);
+       fdi_ptrs = calloc(bit_count(enabled_buffers) + 1 /* NULL terminator */, sizeof *fdi_ptrs);
        if (!fdi_ptrs)
                return -ENOMEM;
 
        __attribute__ ((cleanup(list_clear_free_contents))) list_head used_paths = NULL;
 
-       unsigned int mask = ~0;
+       mask = ~0;
        for (int i = 0; i < LOG_ID_MAX; ++i) {
                mask &= ~(1u << i);
        }
@@ -30,7 +34,7 @@ int create_initial_fdis(struct fd_info ***fdis, int enabled_buffers, bool is_pip
                goto failure;
        }
 
-       int fdi_cnt = 0;
+       fdi_cnt = 0;
        for (int i = 0; i < LOG_ID_MAX; ++i) {
                if (!bit_test(enabled_buffers, i))
                        continue;
@@ -51,7 +55,7 @@ int create_initial_fdis(struct fd_info ***fdis, int enabled_buffers, bool is_pip
                        goto failure;
                }
 
-               int r = fdi->ops->create(fdi, conf, bufname, &used_paths);
+               r = fdi->ops->create(fdi, conf, bufname, &used_paths);
                if (r < 0) {
                        // TODO: Inform about that again somewhere else
                        fdi_free(fdi);
index 1aca18d..2baaf9a 100644 (file)
@@ -32,6 +32,8 @@ int set_config(const char *filename, int flag, char prio, const char *tag, int l
 
        char buf[BUF_LEN];
        const int flags = O_CREAT | O_WRONLY | flag;
+       int r;
+       ssize_t s;
 
        const int fd = open(filename, flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
        if (fd < 0) {
@@ -40,7 +42,6 @@ int set_config(const char *filename, int flag, char prio, const char *tag, int l
                return ret;
        }
 
-       int r;
        if (limit == FILTER_ALLOW)
                r = snprintf(buf, sizeof buf, "limiter|%s|%c=allow\n", tag, prio);
        else if (limit == FILTER_DENY)
@@ -53,7 +54,7 @@ int set_config(const char *filename, int flag, char prio, const char *tag, int l
                goto finish;
        }
 
-       const ssize_t s = write(fd, buf, r);
+       s = write(fd, buf, r);
        if (s < 0) {
                r = -errno;
                perror("error writing config file");