]> arthur.barton.de Git - netdata.git/commitdiff
improvements identified via static code analysis with cppcheck
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 13 Nov 2016 10:20:27 +0000 (12:20 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 13 Nov 2016 10:20:27 +0000 (12:20 +0200)
24 files changed:
src/apps_plugin.c
src/common.c
src/daemon.c
src/eval.c
src/health.c
src/ipc.c
src/log.c
src/plugin_idlejitter.c
src/plugin_proc.c
src/plugins_d.c
src/proc_diskstats.c
src/proc_interrupts.c
src/proc_meminfo.c
src/proc_net_dev.c
src/proc_net_rpc_nfs.c
src/proc_net_rpc_nfsd.c
src/proc_net_snmp6.c
src/proc_net_stat_conntrack.c
src/proc_self_mountinfo.c
src/proc_softirqs.c
src/proc_vmstat.c
src/procfile.c
src/rrd.c
src/sys_fs_cgroup.c

index f22a575ba596f9bcb9805d08e24d7b9fe71150b1..d367fc35f3618cf2a4eca47ae4d0da017ff5013a 100644 (file)
@@ -2787,7 +2787,6 @@ int main(int argc, char **argv)
     procfile_adaptive_initial_allocation = 1;
 
     time_t started_t = time(NULL);
-    time_t current_t;
     get_system_HZ();
     get_system_pid_max();
     get_system_cpus();
@@ -2831,12 +2830,12 @@ int main(int argc, char **argv)
 
 #ifndef PROFILING_MODE
     unsigned long long sunext = (time(NULL) - (time(NULL) % update_every) + update_every) * 1000000ULL;
-    unsigned long long sunow;
 #endif /* PROFILING_MODE */
 
     global_iterations_counter = 1;
     for(;1; global_iterations_counter++) {
 #ifndef PROFILING_MODE
+        unsigned long long sunow;
         // delay until it is our time to run
         while((sunow = time_usec()) < sunext)
             sleep_usec(sunext - sunow);
@@ -2878,7 +2877,7 @@ int main(int argc, char **argv)
         if(unlikely(debug))
             fprintf(stderr, "apps.plugin: done Loop No %llu\n", global_iterations_counter);
 
-        current_t = time(NULL);
+        time_t current_t = time(NULL);
 
 #ifndef PROFILING_MODE
         // restart check (14400 seconds)
index ce348d79479ab1b3dd7564ba5f98733a999648a8..fa69bff8568d719c765fa1452bca7940b95663e6 100644 (file)
@@ -864,11 +864,9 @@ uint32_t simple_hash(const char *name) {
 */
 
 void strreverse(char *begin, char *end) {
-    char aux;
-
     while (end > begin) {
         // clearer code.
-        aux = *end;
+        char aux = *end;
         *end-- = *begin;
         *begin++ = aux;
     }
@@ -905,11 +903,10 @@ void *mymmap(const char *filename, size_t size, int flags, int ksm) {
 #ifdef MADV_MERGEABLE
     static int log_madvise_2 = 1, log_madvise_3 = 1;
 #endif
-    int fd;
     void *mem = NULL;
 
     errno = 0;
-    fd = open(filename, O_RDWR | O_CREAT | O_NOATIME, 0664);
+    int fd = open(filename, O_RDWR | O_CREAT | O_NOATIME, 0664);
     if (fd != -1) {
         if (lseek(fd, size, SEEK_SET) == (off_t) size) {
             if (write(fd, "", 1) == 1) {
@@ -1090,14 +1087,12 @@ int snprintfz(char *dst, size_t n, const char *fmt, ...) {
 
 int processors = 1;
 long get_system_cpus(void) {
-    procfile *ff = NULL;
-
     processors = 1;
 
     char filename[FILENAME_MAX + 1];
     snprintfz(filename, FILENAME_MAX, "%s/proc/stat", global_host_prefix);
 
-    ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT);
+    procfile *ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT);
     if(!ff) {
         error("Cannot open file '%s'. Assuming system has %d processors.", filename, processors);
         return processors;
@@ -1127,11 +1122,9 @@ long get_system_cpus(void) {
 
 pid_t pid_max = 32768;
 pid_t get_system_pid_max(void) {
-    procfile *ff = NULL;
-
     char filename[FILENAME_MAX + 1];
     snprintfz(filename, FILENAME_MAX, "%s/proc/sys/kernel/pid_max", global_host_prefix);
-    ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT);
+    procfile *ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT);
     if(!ff) {
         error("Cannot open file '%s'. Assuming system supports %d pids.", filename, pid_max);
         return pid_max;
index fb57be141d6da1801650d7112a242c4ad4f73034..2453012e87ede4859a43183b8a8bb20a060c3841 100644 (file)
@@ -114,7 +114,6 @@ int become_user(const char *username, int pid_fd)
             error("Cannot set supplementary groups for user '%s'", username);
 
         freez(supplementary_groups);
-        supplementary_groups = NULL;
         ngroups = 0;
     }
 
@@ -251,10 +250,8 @@ int become_daemon(int dont_fork, const char *user)
         create_needed_dir(VARLIB_DIR, getuid(), getgid());
     }
 
-    if(pidfd != -1) {
+    if(pidfd != -1)
         close(pidfd);
-        pidfd = -1;
-    }
 
     return(0);
 }
index 94c978e3eaaa59639d928907fef6e9b07f622ee1..a4450f92c7c586d9e57353f6d32c40b900d5d3ff 100644 (file)
@@ -1031,9 +1031,7 @@ static inline EVAL_NODE *parse_rest_of_expression(const char **string, int *erro
 
 // high level function to parse an expression or a sub-expression
 static inline EVAL_NODE *parse_full_expression(const char **string, int *error) {
-    EVAL_NODE *op1 = NULL;
-
-    op1 = parse_one_full_operand(string, error);
+    EVAL_NODE *op1 = parse_one_full_operand(string, error);
     if(!op1) {
         *error = EVAL_ERROR_MISSING_OPERAND;
         return NULL;
@@ -1081,7 +1079,6 @@ int expression_evaluate(EVAL_EXPRESSION *exp) {
 EVAL_EXPRESSION *expression_parse(const char *string, const char **failed_at, int *error) {
     const char *s = string;
     int err = EVAL_ERROR_OK;
-    unsigned long pos = 0;
 
     EVAL_NODE *op = parse_full_expression(&s, &err);
 
@@ -1097,7 +1094,7 @@ EVAL_EXPRESSION *expression_parse(const char *string, const char **failed_at, in
     if (error) *error = err;
 
     if(!op) {
-        pos = s - string + 1;
+        unsigned long pos = s - string + 1;
         error("failed to parse expression '%s': %s at character %lu (i.e.: '%s').", string, expression_strerror(err), pos, s);
         return NULL;
     }
index 876acac56bd1a0dd498ee2f527c6a1b44b901887..280c913f41a92d8c4f686c42f87e832dec299007 100644 (file)
@@ -141,13 +141,12 @@ static inline void health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae) {
 
 static inline ssize_t health_alarm_log_read(RRDHOST *host, FILE *fp, const char *filename) {
     static uint32_t max_unique_id = 0, max_alarm_id = 0;
-    ssize_t loaded = -1, updated = -1, errored = -1, duplicate = -1;
 
     errno = 0;
 
     char *s, *buf = mallocz(65536 + 1);
     size_t line = 0, len = 0;
-    loaded = updated = errored = duplicate = 0;
+    ssize_t loaded = 0, updated = 0, errored = 0, duplicate = 0;
 
     pthread_rwlock_rdlock(&host->health_log.alarm_log_rwlock);
 
index 6177362566ab69dbd25e8d7dcebcb47a5178ea72..3cf76513dce8b27bbf46367fce5d9f54a7451adf 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -138,7 +138,6 @@ printf ("allocated semaphores = %d\n", status.semaem);
 */
 
 static inline int ipc_sem_get_status(struct ipc_status *st) {
-    static int error_shown = 0;
     struct seminfo seminfo;
     union semun arg;
 
@@ -146,6 +145,7 @@ static inline int ipc_sem_get_status(struct ipc_status *st) {
 
     if(unlikely(semctl (0, 0, SEM_INFO, arg) < 0)) {
         /* kernel not configured for semaphores */
+        static int error_shown = 0;
         if(unlikely(!error_shown)) {
             error("IPC: kernel is not configured for semaphores");
             error_shown = 1;
index 86716987aeba7eab4dbab471732d5dcafa4a9da3..bf2ad6b381fb6531f0f436ebe86411451c1e9074 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -24,7 +24,7 @@ void syslog_init(void) {
 }
 
 int open_log_file(int fd, FILE **fp, const char *filename, int *enabled_syslog) {
-    int f, t;
+    int f;
 
     if(!filename || !*filename || !strcmp(filename, "none"))
         filename = "/dev/null";
@@ -64,7 +64,7 @@ int open_log_file(int fd, FILE **fp, const char *filename, int *enabled_syslog)
 
     if(fd != f && fd != -1) {
         // it automatically closes
-        t = dup2(f, fd);
+        int t = dup2(f, fd);
         if (t == -1) {
             error("Cannot dup2() new fd %d to old fd %d for '%s'", f, fd, filename);
             close(f);
index 30c6d87088157aa6122e3bf0659cb23be40190fe..a9b340ab00897637b7f047f1c3e3c832b55f4059 100644 (file)
@@ -34,7 +34,7 @@ void *cpuidlejitter_main(void *ptr)
         while(susec < (rrd_update_every * 1000000ULL)) {
 
             gettimeofday(&before, NULL);
-            usleep(sleep_ms * 1000);
+            sleep_usec(sleep_ms * 1000);
             gettimeofday(&after, NULL);
 
             // calculate the time it took for a full loop
index 1c461dabd301cb0e8952a2958d2923844b696726..3e19d85a6bbd64e236cae065bffdb80ba45ed40c 100644 (file)
@@ -63,9 +63,9 @@ void *proc_main(void *ptr)
 
     // the next time we will run - aligned properly
     unsigned long long sunext = (time(NULL) - (time(NULL) % rrd_update_every) + rrd_update_every) * 1000000ULL;
-    unsigned long long sunow;
 
     for(;;) {
+        unsigned long long sunow;
         if(unlikely(netdata_exit)) break;
 
         // delay until it is our time to run
index 6af9c21e0aad3e6790f9f40e5ed528fc42aba651..4053653233bb0f181e5723075999e1c8227a5b57 100644 (file)
@@ -121,7 +121,6 @@ void *pluginsd_worker_thread(void *arg)
         info("PLUGINSD: '%s' running on pid %d", cd->fullfilename, cd->pid);
 
         RRDSET *st = NULL;
-        char *s;
         uint32_t hash;
 
         while(likely(fgets(line, PLUGINSD_LINE_MAX, fp) != NULL)) {
@@ -132,7 +131,7 @@ void *pluginsd_worker_thread(void *arg)
             // debug(D_PLUGINSD, "PLUGINSD: %s: %s", cd->filename, line);
 
             int w = pluginsd_split_words(line, words, MAX_WORDS);
-            s = words[0];
+            char *s = words[0];
             if(unlikely(!s || !*s || !w)) {
                 // debug(D_PLUGINSD, "PLUGINSD: empty line");
                 continue;
index 7ff857785edeba9cb240160b31e8e5bb766ed2e1..52712c25a24ed96a0cabab4b571469e27580bdf6 100644 (file)
@@ -480,7 +480,6 @@ int do_proc_diskstats(int update_every, unsigned long long dt) {
     if(unlikely(!ff)) return 0; // we return 0, so that we will retry to open it next time
 
     uint32_t lines = procfile_lines(ff), l;
-    uint32_t words;
 
     // this is smart enough not to reload it every time
     mountinfo_reload(0);
@@ -500,7 +499,7 @@ int do_proc_diskstats(int update_every, unsigned long long dt) {
                             last_writes = 0, last_writesectors = 0, last_writems = 0,
                             last_busy_ms = 0;
 
-        words = procfile_linewords(ff, l);
+        uint32_t words = procfile_linewords(ff, l);
         if(unlikely(words < 14)) continue;
 
         major           = strtoul(procfile_lineword(ff, l, 0), NULL, 10);
index c652693a7273af4174dc43264e559c04c224d787..14215de68a24f497f208f72694ddffb60fe692cf 100644 (file)
@@ -52,7 +52,7 @@ int do_proc_interrupts(int update_every, unsigned long long dt) {
         return 0; // we return 0, so that we will retry to open it next time
 
     uint32_t lines = procfile_lines(ff), l;
-    uint32_t words = procfile_linewords(ff, 0), w;
+    uint32_t words = procfile_linewords(ff, 0);
 
     if(unlikely(!lines)) {
         error("Cannot read /proc/interrupts, zero lines reported.");
@@ -61,6 +61,7 @@ int do_proc_interrupts(int update_every, unsigned long long dt) {
 
     // find how many CPUs are there
     if(unlikely(cpus == -1)) {
+        uint32_t w;
         cpus = 0;
         for(w = 0; w < words ; w++) {
             if(unlikely(strncmp(procfile_lineword(ff, 0, w), "CPU", 3) == 0))
index 0e5e14fd20e9d91b0015718a2552cac69fb812cf..11b41be7bd3dc7ce9d178ce5a4fa3541fe6bfcc3 100644 (file)
@@ -114,7 +114,6 @@ int do_proc_meminfo(int update_every, unsigned long long dt) {
         return 0; // we return 0, so that we will retry to open it next time
 
     uint32_t lines = procfile_lines(ff), l;
-    uint32_t words;
 
     int hwcorrupted = 0;
 
@@ -162,7 +161,7 @@ int do_proc_meminfo(int update_every, unsigned long long dt) {
             HardwareCorrupted = 0;
 
     for(l = 0; l < lines ;l++) {
-        words = procfile_linewords(ff, l);
+        uint32_t words = procfile_linewords(ff, l);
         if(unlikely(words < 2)) continue;
 
         char *name = procfile_lineword(ff, l, 0);
index 53981182a4b22ad5158534e4f0db9cf9596fe276..33d140c471f1c97254b4793b769639b2ee8cdd64 100644 (file)
@@ -29,14 +29,13 @@ int do_proc_net_dev(int update_every, unsigned long long dt) {
     if(do_events == -1)     do_events       = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "frames, collisions, carrier counters for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
 
     uint32_t lines = procfile_lines(ff), l;
-    uint32_t words;
 
     char *iface;
     unsigned long long rbytes, rpackets, rerrors, rdrops, rfifo, rframe, rcompressed, rmulticast;
     unsigned long long tbytes, tpackets, terrors, tdrops, tfifo, tcollisions, tcarrier, tcompressed;
 
     for(l = 2; l < lines ;l++) {
-        words = procfile_linewords(ff, l);
+        uint32_t words = procfile_linewords(ff, l);
         if(words < 17) continue;
 
         iface       = procfile_lineword(ff, l, 0);
index 98acdd8145688e5dc2590fa50df608b02cc75ae1..86e2f70c0d23a74f8f1e1a9edf2ab2281ef93663 100644 (file)
@@ -159,14 +159,13 @@ int do_proc_net_rpc_nfs(int update_every, unsigned long long dt) {
     if(do_proc4) do_proc4 = 1;
 
     uint32_t lines = procfile_lines(ff), l;
-    uint32_t words;
 
     char *type;
     unsigned long long net_count = 0, net_udp_count = 0, net_tcp_count = 0, net_tcp_connections = 0;
     unsigned long long rpc_calls = 0, rpc_retransmits = 0, rpc_auth_refresh = 0;
 
     for(l = 0; l < lines ;l++) {
-        words = procfile_linewords(ff, l);
+        uint32_t words = procfile_linewords(ff, l);
         if(!words) continue;
 
         type        = procfile_lineword(ff, l, 0);
index 817e6c86aabc478e4da930c6339d9a8f23e2dafb..e0092c722d6ac15e8556303df8b411990c718978 100644 (file)
@@ -253,7 +253,6 @@ int do_proc_net_rpc_nfsd(int update_every, unsigned long long dt) {
     if(do_proc4ops) do_proc4ops = 1;
 
     uint32_t lines = procfile_lines(ff), l;
-    uint32_t words;
 
     char *type;
     unsigned long long rc_hits = 0, rc_misses = 0, rc_nocache = 0;
@@ -265,7 +264,7 @@ int do_proc_net_rpc_nfsd(int update_every, unsigned long long dt) {
     unsigned long long rpc_calls = 0, rpc_bad_format = 0, rpc_bad_auth = 0, rpc_bad_client = 0;
 
     for(l = 0; l < lines ;l++) {
-        words = procfile_linewords(ff, l);
+        uint32_t words = procfile_linewords(ff, l);
         if(!words) continue;
 
         type = procfile_lineword(ff, l, 0);
index 34c01a2f9c23b94d746cb333ab61788be6036d59..b7ec65c08cb9e967bac8e0db6a4c9d2759b02ec8 100644 (file)
@@ -253,7 +253,6 @@ int do_proc_net_snmp6(int update_every, unsigned long long dt) {
         return 0; // we return 0, so that we will retry to open it next time
 
     uint32_t lines = procfile_lines(ff), l;
-    uint32_t words;
 
     unsigned long long Ip6InReceives = 0ULL;
     unsigned long long Ip6InHdrErrors = 0ULL;
@@ -349,7 +348,7 @@ int do_proc_net_snmp6(int update_every, unsigned long long dt) {
     unsigned long long UdpLite6InCsumErrors = 0ULL;
 
     for(l = 0; l < lines ;l++) {
-        words = procfile_linewords(ff, l);
+        uint32_t words = procfile_linewords(ff, l);
         if(unlikely(words < 2)) {
             if(unlikely(words)) error("Cannot read /proc/net/snmp6 line %u. Expected 2 params, read %u.", l, words);
             continue;
index b1fc1f3313367509bdfc03018bfc2098a94bbece..807a9baeb828de677120713db2889c5bb949f99b 100644 (file)
@@ -31,13 +31,12 @@ int do_proc_net_stat_conntrack(int update_every, unsigned long long dt) {
         return 0; // we return 0, so that we will retry to open it next time
 
     uint32_t lines = procfile_lines(ff), l;
-    uint32_t words;
 
     unsigned long long aentries = 0, asearched = 0, afound = 0, anew = 0, ainvalid = 0, aignore = 0, adelete = 0, adelete_list = 0,
         ainsert = 0, ainsert_failed = 0, adrop = 0, aearly_drop = 0, aicmp_error = 0, aexpect_new = 0, aexpect_create = 0, aexpect_delete = 0, asearch_restart = 0;
 
     for(l = 1; l < lines ;l++) {
-        words = procfile_linewords(ff, l);
+        uint32_t words = procfile_linewords(ff, l);
         if(unlikely(words < 17)) {
             if(unlikely(words)) error("Cannot read /proc/net/stat/nf_conntrack line. Expected 17 params, read %u.", words);
             continue;
index 3b1ecded3cf92316f70704f1911abb6d0beeebef..d2708f2e4f3919cd43e107fc569fea8b3916da58 100644 (file)
@@ -159,11 +159,9 @@ static char *strdupz_decoding_octal(const char *string) {
 
 // read the whole mountinfo into a linked list
 struct mountinfo *mountinfo_read() {
-    procfile *ff = NULL;
-
     char filename[FILENAME_MAX + 1];
     snprintfz(filename, FILENAME_MAX, "%s/proc/self/mountinfo", global_host_prefix);
-    ff = procfile_open(filename, " \t", PROCFILE_FLAG_DEFAULT);
+    procfile *ff = procfile_open(filename, " \t", PROCFILE_FLAG_DEFAULT);
     if(unlikely(!ff)) {
         snprintfz(filename, FILENAME_MAX, "%s/proc/1/mountinfo", global_host_prefix);
         ff = procfile_open(filename, " \t", PROCFILE_FLAG_DEFAULT);
index 5346026c9e825c1ec329ad50bca94e626aff722e..818a6a7098294c950ce1517e9215ae632b4ddaac 100644 (file)
@@ -50,7 +50,7 @@ int do_proc_softirqs(int update_every, unsigned long long dt) {
     if(unlikely(!ff)) return 0; // we return 0, so that we will retry to open it next time
 
     uint32_t lines = procfile_lines(ff), l;
-    uint32_t words = procfile_linewords(ff, 0), w;
+    uint32_t words = procfile_linewords(ff, 0);
 
     if(unlikely(!lines)) {
         error("Cannot read /proc/softirqs, zero lines reported.");
@@ -59,6 +59,7 @@ int do_proc_softirqs(int update_every, unsigned long long dt) {
 
     // find how many CPUs are there
     if(unlikely(cpus == -1)) {
+        uint32_t w;
         cpus = 0;
         for(w = 0; w < words ; w++) {
             if(unlikely(strncmp(procfile_lineword(ff, 0, w), "CPU", 3) == 0))
index 3615f56f6333510adf9ff45b8919b7cbc22cf3c5..a8058398409077a2db021c43405e6794e0cc2672 100644 (file)
@@ -209,7 +209,6 @@ int do_proc_vmstat(int update_every, unsigned long long dt) {
     if(unlikely(!ff)) return 0; // we return 0, so that we will retry to open it next time
 
     uint32_t lines = procfile_lines(ff), l;
-    uint32_t words;
 
     // unsigned long long allocstall = 0ULL;
     // unsigned long long compact_blocks_moved = 0ULL;
@@ -305,7 +304,7 @@ int do_proc_vmstat(int update_every, unsigned long long dt) {
     // unsigned long long unevictable_pgs_stranded = 0ULL;
 
     for(l = 0; l < lines ;l++) {
-        words = procfile_linewords(ff, l);
+        uint32_t words = procfile_linewords(ff, l);
         if(unlikely(words < 2)) {
             if(unlikely(words)) error("Cannot read /proc/vmstat line %u. Expected 2 params, read %u.", l, words);
             continue;
index ee7378713fc355414e37e2cda68c1b9c14bb8ab1..31bdb5e25786aa01a57e0c33ecd407d4d5328bb4 100644 (file)
@@ -267,12 +267,12 @@ cleanup:
 procfile *procfile_readall(procfile *ff) {
     debug(D_PROCFILE, PF_PREFIX ": Reading file '%s'.", ff->filename);
 
-    ssize_t s, r = 1, x;
+    ssize_t r = 1;
     ff->len = 0;
 
     while(likely(r > 0)) {
-        s = ff->len;
-        x = ff->size - s;
+        ssize_t s = ff->len;
+        ssize_t x = ff->size - s;
 
         if(unlikely(!x)) {
             debug(D_PROCFILE, PF_PREFIX ": Expanding data buffer for file '%s'.", ff->filename);
@@ -316,13 +316,13 @@ procfile *procfile_readall(procfile *ff) {
 
 static void procfile_set_separators(procfile *ff, const char *separators) {
     static char def[256] = { [0 ... 255] = 0 };
-    int i;
 
     if(unlikely(!def[255])) {
         // this is thread safe
         // we check that the last byte is non-zero
         // if it is zero, multiple threads may be executing this at the same time
         // setting in def[] the exact same values
+        int i;
         for(i = 0; likely(i < 256) ;i++) {
             if(unlikely(i == '\n' || i == '\r')) def[i] = PF_CHAR_IS_NEWLINE;
             else if(unlikely(isspace(i) || !isprint(i))) def[i] = PF_CHAR_IS_SEPARATOR;
@@ -443,16 +443,16 @@ procfile *procfile_reopen(procfile *ff, const char *filename, const char *separa
 
 void procfile_print(procfile *ff) {
     uint32_t lines = procfile_lines(ff), l;
-    uint32_t words, w;
     char *s;
 
     debug(D_PROCFILE, "File '%s' with %u lines and %u words", ff->filename, ff->lines->len, ff->words->len);
 
     for(l = 0; likely(l < lines) ;l++) {
-        words = procfile_linewords(ff, l);
+        uint32_t words = procfile_linewords(ff, l);
 
         debug(D_PROCFILE, " line %u starts at word %u and has %u words", l, ff->lines->lines[l].first, ff->lines->lines[l].words);
 
+        uint32_t w;
         for(w = 0; likely(w < words) ;w++) {
             s = procfile_lineword(ff, l, w);
             debug(D_PROCFILE, "     [%u.%u] '%s'", l, w, s);
index 5b218fa81c125ab6b853548f76751b178c7e4606..8e2d76afc8877e1710c079b3d469dc6a916ea84a 100644 (file)
--- a/src/rrd.c
+++ b/src/rrd.c
@@ -474,11 +474,10 @@ RRDSET *rrdset_create(const char *type, const char *id, const char *name, const
 
     char fullid[RRD_ID_LENGTH_MAX + 1];
     char fullfilename[FILENAME_MAX + 1];
-    RRDSET *st = NULL;
 
     snprintfz(fullid, RRD_ID_LENGTH_MAX, "%s.%s", type, id);
 
-    st = rrdset_find(fullid);
+    RRDSET *st = rrdset_find(fullid);
     if(st) {
         error("Cannot create rrd stats for '%s', it already exists.", fullid);
         return st;
index 5e49f33e8b5f866c426dd3a98f683f953233a485..cef7cb449c2bcb93c1edcffd4581622e374cb647 100644 (file)
@@ -269,7 +269,7 @@ void cgroup_read_cpuacct_usage(struct cpuacct_usage *ca) {
         }
 
         unsigned long i = procfile_linewords(ff, 0);
-        if(i <= 0) return;
+        if(i == 0) return;
 
         // we may have 1 more CPU reported
         while(i > 0) {
@@ -1437,11 +1437,11 @@ void *cgroups_main(void *ptr)
 
     // the next time we will run - aligned properly
     unsigned long long sunext = (time(NULL) - (time(NULL) % rrd_update_every) + rrd_update_every) * 1000000ULL;
-    unsigned long long sunow;
 
     RRDSET *stcpu_thread = NULL;
 
     for(;;) {
+        unsigned long long sunow;
         if(unlikely(netdata_exit)) break;
 
         // delay until it is our time to run