Fix various SVACE static analysis warnings 64/187464/3 accepted/tizen/unified/20180831.061032 submit/tizen/20180829.051003
authorMichal Bloch <m.bloch@samsung.com>
Wed, 22 Aug 2018 16:41:11 +0000 (18:41 +0200)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Wed, 29 Aug 2018 02:59:54 +0000 (02:59 +0000)
Change-Id: I1ff2570548bab4e7877380633529ecdc7fafd22a
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/logger/logger.c
src/shared/logprint.c
src/shared/queued_entry.c
src/tests/filters.c

index 01f299d..282f23b 100755 (executable)
@@ -1174,22 +1174,19 @@ static int parse_command_line(const char *cmdl, struct writer *wr, struct logger
                retval = logfile_open(&reader->file);
                if (retval < 0)
                        goto cleanup;
-       } else {
-               // we have got no file path nor dlogutil connection to write to - unable to proceed
-               retval = wr ? 0 : -EINVAL;
-               if (retval < 0)
-                       goto cleanup;
-
+       } else if (wr) {
                int write_fd = -1, read_fd = -1;
                if (create_fifo_fds(wr->fd_entity.fd, &write_fd, &read_fd) < 0)
                        goto cleanup;
 
                set_write_fd_entity(&reader->fd_entity, write_fd);
-               assert(wr);
                retval = send_pipe(wr->fd_entity.fd, read_fd);
-               close(read_fd);
+               if (read_fd > 0)
+                       close(read_fd);
                if (retval)
                        goto cleanup;
+       } else {
+               retval = -EINVAL;
        }
 cleanup:
        /* recycle for further usage */
@@ -1804,9 +1801,14 @@ static int initialize_epoll_size(struct epoll_event **events, unsigned *size)
        assert(events);
        assert(size);
 
-       *size = 16U;
-       *events = malloc(*size * sizeof **events);
-       return !*events ? -ENOMEM : 0;
+       static const size_t default_size = 16U;
+       typeof(*events) ev = malloc(default_size * sizeof *ev);
+       if (!ev)
+               return -ENOMEM;
+
+       *events = ev;
+       *size = default_size;
+       return 0;
 }
 
 /**
@@ -1839,8 +1841,10 @@ static int do_logger(struct logger* server)
                if (nfds < 0 && errno == EINTR)
                        continue;
 
-               if (nfds < 0)
-                       return -errno;
+               if (nfds < 0) {
+                       r = -errno;
+                       break;
+               }
 
                for (int i = 0; i < nfds; i++) {
                        struct fd_entity* entity = (struct fd_entity*) events[i].data.ptr;
index 9ab7746..78c50b9 100644 (file)
@@ -107,7 +107,7 @@ static FilterInfo *filterinfo_clone(FilterInfo *p_info)
 
        switch (p_info->type) {
        case FILTER_TAG_AND_PRIO:
-               return filterinfo_new(p_info->tnp.tag, p_info->tnp.pri, p_info->tnp.exactPri, p_info->tnp.prefix, FILTERINFO_PID_NONE, FILTERINFO_TID_NONE);
+               return filterinfo_new(p_info->tnp.tag, p_info->tnp.pri, p_info->tnp.prefix, p_info->tnp.exactPri, FILTERINFO_PID_NONE, FILTERINFO_TID_NONE);
        case FILTER_PID:
                return filterinfo_new(NULL, 0, false, false, p_info->pid, FILTERINFO_TID_NONE);
        case FILTER_TID:
@@ -669,6 +669,8 @@ char *log_format_log_line(
 #else
        ptm = localtime((const time_t*)&time_t_temp);
 #endif
+       if (!ptm)
+               return NULL;
        strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", ptm);
 
        time_t_temp = (time_t)entry->sec_recv_real;
@@ -677,6 +679,9 @@ char *log_format_log_line(
 #else
        ptm = localtime((const time_t*)&time_t_temp);
 #endif
+       if (!ptm)
+               return NULL;
+
        strftime(recvTimeBuf, sizeof(recvTimeBuf), "%m-%d %H:%M:%S", ptm);
 
        strftime(tzBuf, sizeof(tzBuf), "%z", ptm);
index b745cfd..fb7def7 100644 (file)
@@ -170,8 +170,9 @@ int parse_kmsg_message(char *buffer, struct logger_entry_with_msg *lem, int buff
                le->tag_len = i - 1; \
                break; \
        } \
-       if (le->tag_len == -1) \
-               ; /* ignore for now */ \
+       if (le->tag_len == -1) { \
+               /* ignore for now */ \
+       } \
        payload_size--; /* there's priority at first byte which is not a part of a message */ \
        le->len = sizeof *le + payload_size; \
        le->pid = xle->pid; \
index 7cc760e..56c1c99 100644 (file)
@@ -129,9 +129,8 @@ int check_print_line_tag_prior(int line, log_format *p_format, char *tag, int pr
        entry.header.tid = 0;
        entry.header.pid = 0;
        entry.header.priority = priority;
-       strncpy(entry.msg, tag, strlen(tag));
-       entry.msg[strlen(tag)] = '\0'; /* tag delimiter */
-       entry.msg[strlen(tag) + 1] = '\0'; /* empty msg */
+       strncpy(entry.msg, tag, strlen(tag) + 1);
+       entry.msg[strlen(tag) + 1] = '\0'; // second NULL terminator: empty message
        entry.header.len = sizeof(struct logger_entry) + strlen(tag) + 2;
 
        if (expected != log_should_print_line(p_format, &entry.header)) {
@@ -227,7 +226,7 @@ int main()
 
        log_add_filter_rule(p_format, "crap:*");
 
-       const size_t taglen = strlen("crap");
+       static const size_t taglen = sizeof "crap" - 1;
 
        entry.header.priority = DLOG_VERBOSE;
        strncpy(entry.msg, "crap", taglen);