Reduce compiler complaints by adding helpful asserts 69/261469/4
authorMateusz Majewski <m.majewski2@samsung.com>
Mon, 19 Jul 2021 12:59:51 +0000 (14:59 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Tue, 17 Aug 2021 11:59:30 +0000 (13:59 +0200)
Change-Id: I3975c8399cfde2718aa3711d8ad1df46124bd842

src/logutil/logutil.c
src/shared/logprint.c

index 13f389a..34299ba 100644 (file)
@@ -366,6 +366,8 @@ int main(int argc, char **argv)
        case ACTION_CLEAR:
                r = for_each_buffer(enabled_buffers, clear_buffer);
                break;
+       default:
+               assert(false);
        }
 
        if (r < 0) {
index b396921..f49020d 100644 (file)
@@ -880,7 +880,9 @@ static int resolve_write(int fd, struct log_write_buffer *wrbuf, const char *rea
 static void buf_add_milisec(char *buf, int32_t nsec)
 {
        *(buf++) = '.';
-       snprintf(buf, MILISEC_SIZE, "%03d", NSEC_TO_MSEC(nsec));
+       int32_t msec = NSEC_TO_MSEC(nsec);
+       assert(msec >= 0 && msec < 1000);
+       snprintf(buf, MILISEC_SIZE, "%03d", msec);
 }
 
 static char *buf_add_time(char *buf, size_t max_len, const dlogutil_entry_s *entry,