@cryptotaxi247 / netdata-1 / commits / 4ff05c29d

more cleanup identified by cppcheck

Costa Tsaousis (ktsaou) committed Dec 26, 2017 at 06:47 UTC 4ff05c29dcdcd1cf9a4ad145a90290f0589b6422
7 files changed +17 -7
cppcheck.sh
+3
@@ -1,5 +1,7 @@
1 #!/usr/bin/env bash
2
3 +# echo >>/tmp/cppcheck.log "cppcheck ${*}"
4 +
5 cppcheck=$(which cppcheck 2>/dev/null || command -v cppcheck 2>/dev/null)
6 [ -z "${cppcheck}" ] && echo >&2 "install cppcheck." && exit 1
7
@@ -27,4 +29,5 @@ shift
29 --force \
30 --enable=warning,performance,portability,information \
31 --suppress="unusedFunction:*" \
32 + --suppress="nullPointerRedundantCheck:*" \
33 "${file}" "${@}"
netdata.cppcheck
+4 -1
@@ -4,10 +4,13 @@
4 <builddir>cppcheck-build</builddir>
5 <includedir>
6 <dir name=".."/>
7 - <dir name="/usr/include"/>
7 </includedir>
8 <libraries>
9 <library>gnu</library>
10 <library>posix</library>
11 </libraries>
12 + <suppressions>
13 + <suppression>nullPointerRedundantCheck</suppression>
14 + <suppression>unusedFunction</suppression>
15 + </suppressions>
16 </project>
src/freeipmi_plugin.c
+4
@@ -538,6 +538,10 @@ static void excluded_record_ids_parse(const char *s) {
538
539 if(n != 0) {
540 excluded_record_ids = realloc(excluded_record_ids, (excluded_record_ids_length + 1) * sizeof(int));
541 + if(!excluded_record_ids) {
542 + fprintf(stderr, "freeipmi.plugin: failed to allocate memory. Exiting.");
543 + exit(1);
544 + }
545 excluded_record_ids[excluded_record_ids_length++] = (int)n;
546 }
547 }
src/proc_stat.c
+1 -1
@@ -54,7 +54,7 @@ static int read_per_core_files(struct cpu_chart *all_cpu_charts, size_t len, siz
54 }
55
56 ssize_t ret = read(f->fd, buf, 50);
57 - if(unlikely(ret == -1)) {
57 + if(unlikely(ret < 0)) {
58 // cannot read that file
59
60 error("Cannot read file '%s'", f->filename);
src/rrd2json.h
+1 -1
@@ -77,6 +77,6 @@ extern int rrdset2anything_api_v1(RRDSET *st, BUFFER *out, BUFFER *dimensions, u
77
78 extern int rrdset2value_api_v1(RRDSET *st, BUFFER *wb, calculated_number *n, const char *dimensions, long points
79 , long long after, long long before, int group_method, uint32_t options
80 - , time_t *db_before, time_t *db_after, int *value_is_null);
80 + , time_t *db_after, time_t *db_before, int *value_is_null);
81
82 #endif /* NETDATA_RRD2JSON_H */
src/sys_kernel_mm_ksm.c
+3 -3
@@ -22,10 +22,10 @@ KSM_NAME_VALUE values[] = {
22 int do_sys_kernel_mm_ksm(int update_every, usec_t dt) {
23 (void)dt;
24 static procfile *ff_pages_shared = NULL, *ff_pages_sharing = NULL, *ff_pages_unshared = NULL, *ff_pages_volatile = NULL, *ff_pages_to_scan = NULL;
25 - static long page_size = -1;
25 + static unsigned long page_size = 0;
26
27 - if(unlikely(page_size == -1))
28 - page_size = sysconf(_SC_PAGESIZE);
27 + if(unlikely(page_size == 0))
28 + page_size = (unsigned long)sysconf(_SC_PAGESIZE);
29
30 if(unlikely(!ff_pages_shared)) {
31 snprintfz(values[PAGES_SHARED].filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/sys/kernel/mm/ksm/pages_shared");
src/unit_test.c
+1 -1
@@ -1086,7 +1086,7 @@ int run_test(struct test *test)
1086 int errors = 0;
1087
1088 if(st->counter != test->result_entries) {
1089 - fprintf(stderr, " %s stored %lu entries, but we were expecting %lu, ### E R R O R ###\n", test->name, st->counter, test->result_entries);
1089 + fprintf(stderr, " %s stored %zu entries, but we were expecting %lu, ### E R R O R ###\n", test->name, st->counter, test->result_entries);
1090 errors++;
1091 }
1092