diff options
author | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2017-12-26 06:47:56 +0200 |
---|---|---|
committer | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2017-12-26 06:47:56 +0200 |
commit | 4ff05c29dcdcd1cf9a4ad145a90290f0589b6422 (patch) | |
tree | d5d4094d378cdbf0f98bdec57d43b5a5e7ff1e50 | |
parent | a0d391b4b13420c059f5adb43c3fd1c09f41d6ab (diff) |
more cleanup identified by cppcheck
-rwxr-xr-x | cppcheck.sh | 3 | ||||
-rw-r--r-- | netdata.cppcheck | 5 | ||||
-rw-r--r-- | src/freeipmi_plugin.c | 4 | ||||
-rw-r--r-- | src/proc_stat.c | 2 | ||||
-rw-r--r-- | src/rrd2json.h | 2 | ||||
-rw-r--r-- | src/sys_kernel_mm_ksm.c | 6 | ||||
-rw-r--r-- | src/unit_test.c | 2 |
7 files changed, 17 insertions, 7 deletions
diff --git a/cppcheck.sh b/cppcheck.sh index 33a170d673..bfe15d24ce 100755 --- a/cppcheck.sh +++ b/cppcheck.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +# echo >>/tmp/cppcheck.log "cppcheck ${*}" + cppcheck=$(which cppcheck 2>/dev/null || command -v cppcheck 2>/dev/null) [ -z "${cppcheck}" ] && echo >&2 "install cppcheck." && exit 1 @@ -27,4 +29,5 @@ shift --force \ --enable=warning,performance,portability,information \ --suppress="unusedFunction:*" \ + --suppress="nullPointerRedundantCheck:*" \ "${file}" "${@}" diff --git a/netdata.cppcheck b/netdata.cppcheck index 022e03a2ef..c0d6d8786a 100644 --- a/netdata.cppcheck +++ b/netdata.cppcheck @@ -4,10 +4,13 @@ <builddir>cppcheck-build</builddir> <includedir> <dir name=".."/> - <dir name="/usr/include"/> </includedir> <libraries> <library>gnu</library> <library>posix</library> </libraries> + <suppressions> + <suppression>nullPointerRedundantCheck</suppression> + <suppression>unusedFunction</suppression> + </suppressions> </project> diff --git a/src/freeipmi_plugin.c b/src/freeipmi_plugin.c index 9cd736bba2..df4c019a4e 100644 --- a/src/freeipmi_plugin.c +++ b/src/freeipmi_plugin.c @@ -538,6 +538,10 @@ static void excluded_record_ids_parse(const char *s) { if(n != 0) { excluded_record_ids = realloc(excluded_record_ids, (excluded_record_ids_length + 1) * sizeof(int)); + if(!excluded_record_ids) { + fprintf(stderr, "freeipmi.plugin: failed to allocate memory. Exiting."); + exit(1); + } excluded_record_ids[excluded_record_ids_length++] = (int)n; } } diff --git a/src/proc_stat.c b/src/proc_stat.c index 907b659d03..d1aefb73e4 100644 --- a/src/proc_stat.c +++ b/src/proc_stat.c @@ -54,7 +54,7 @@ static int read_per_core_files(struct cpu_chart *all_cpu_charts, size_t len, siz } ssize_t ret = read(f->fd, buf, 50); - if(unlikely(ret == -1)) { + if(unlikely(ret < 0)) { // cannot read that file error("Cannot read file '%s'", f->filename); diff --git a/src/rrd2json.h b/src/rrd2json.h index 864aa8bd90..194bc08e57 100644 --- a/src/rrd2json.h +++ b/src/rrd2json.h @@ -77,6 +77,6 @@ extern int rrdset2anything_api_v1(RRDSET *st, BUFFER *out, BUFFER *dimensions, u extern int rrdset2value_api_v1(RRDSET *st, BUFFER *wb, calculated_number *n, const char *dimensions, long points , long long after, long long before, int group_method, uint32_t options - , time_t *db_before, time_t *db_after, int *value_is_null); + , time_t *db_after, time_t *db_before, int *value_is_null); #endif /* NETDATA_RRD2JSON_H */ diff --git a/src/sys_kernel_mm_ksm.c b/src/sys_kernel_mm_ksm.c index 356315be46..c179c7a259 100644 --- a/src/sys_kernel_mm_ksm.c +++ b/src/sys_kernel_mm_ksm.c @@ -22,10 +22,10 @@ KSM_NAME_VALUE values[] = { int do_sys_kernel_mm_ksm(int update_every, usec_t dt) { (void)dt; static procfile *ff_pages_shared = NULL, *ff_pages_sharing = NULL, *ff_pages_unshared = NULL, *ff_pages_volatile = NULL, *ff_pages_to_scan = NULL; - static long page_size = -1; + static unsigned long page_size = 0; - if(unlikely(page_size == -1)) - page_size = sysconf(_SC_PAGESIZE); + if(unlikely(page_size == 0)) + page_size = (unsigned long)sysconf(_SC_PAGESIZE); if(unlikely(!ff_pages_shared)) { snprintfz(values[PAGES_SHARED].filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/sys/kernel/mm/ksm/pages_shared"); diff --git a/src/unit_test.c b/src/unit_test.c index 821063bafb..fe69a9ab57 100644 --- a/src/unit_test.c +++ b/src/unit_test.c @@ -1086,7 +1086,7 @@ int run_test(struct test *test) int errors = 0; if(st->counter != test->result_entries) { - fprintf(stderr, " %s stored %lu entries, but we were expecting %lu, ### E R R O R ###\n", test->name, st->counter, test->result_entries); + fprintf(stderr, " %s stored %zu entries, but we were expecting %lu, ### E R R O R ###\n", test->name, st->counter, test->result_entries); errors++; } |