From: sanghyeok.oh Date: Thu, 27 Feb 2020 07:37:15 +0000 (+0900) Subject: coverity: Fix coverity issue X-Git-Tag: accepted/tizen/unified/20200228.123730^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=febf3006e796864bd86816f4fd3ed05a2706ed85;p=platform%2Fcore%2Fsystem%2Fdlog.git coverity: Fix coverity issue Coverity: #1124568, #1044318 Change-Id: I87b998521582b7562ac4e056332301cdb7697e54 --- diff --git a/src/libdlogutil/fdi_logger.c b/src/libdlogutil/fdi_logger.c index 73cab62..b31ee75 100644 --- a/src/libdlogutil/fdi_logger.c +++ b/src/libdlogutil/fdi_logger.c @@ -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; diff --git a/src/libdlogutil/logretrieve.c b/src/libdlogutil/logretrieve.c index a555623..a19d79d 100644 --- a/src/libdlogutil/logretrieve.c +++ b/src/libdlogutil/logretrieve.c @@ -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); diff --git a/tests/test_filters.c b/tests/test_filters.c index 1aca18d..2baaf9a 100644 --- a/tests/test_filters.c +++ b/tests/test_filters.c @@ -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");