@cryptotaxi247 / netdata-1 / commits / d6ba820be

Cppcheck fixes (#6386)

* collector: cgroups: Fix a cppcheck warning Cppcheck was throwing the following warning in collectors/cgroups.plugin/cgroup-network.c [collectors/cgroups.plugin/cgroup-network.c:233]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? One of the arguments to switch_namespace() is 'const char *prefix', in this function we were checking if prefix was NULL and if so setting it (local scope wise) to "". While this wasn't technically incorrect in this context. It is also unnecessary as the prefix variable is only passed to the proc_pid_fd() function where the same check happens, so we can simply remove the offending line. Signed-off-by: Andrew Clayton <andrew@zeta.digital-domain.net> * tests/profile: Remove somewhat redundant code cppcheck was throwing a warning in benchmark-line-parsing.c [tests/profile/benchmark-line-parsing.c:648]: (warning) Unnecessary comparison of static strings, this comes from (void)strcmp("1", "2"); in main() That is amongst a group of three function calls preceded by the comment // cache functions But then test1() which uses strcmp() is called twice anyway with the timing result of just the second one used, so the dummy strcmp() call would seem superfluous. I would say the same is true for the call to strtoull() (void)strtoull("123", NULL, 0); as that is also used in test1(). I actually ran this benchmark with and without the calls to all three functions, i.e // cache functions (void)simple_hash2("hello world"); (void)strcmp("1", "2"); (void)strtoull("123", NULL, 0); With the above functions being called test1() average time = 7801604 test2() average time = 1333162 Without those three function calls test1() average time = 7779905 test2() average time = 1321438 Those are the averages of three runs. test1() uses strcmp() & strtoull() and test2() uses simple_hash2(), so in that run, not calling the three functions initially was actually quicker. Subsequent runs of each show similar numbers with each edging the other out, however the difference is in the noise. Signed-off-by: Andrew Clayton <andrew@zeta.digital-domain.net>

Andrew Clayton committed Sep 17, 2019 at 12:42 UTC d6ba820be6149e6e37dea6843d08d5364b46e874
2 files changed -6
collectors/cgroups.plugin/cgroup-network.c
-1
@@ -230,7 +230,6 @@ static struct ns {
230 };
231
232 int switch_namespace(const char *prefix, pid_t pid) {
233 - if(!prefix) prefix = "";
233
234 #ifdef HAVE_SETNS
235
tests/profile/benchmark-line-parsing.c
-5
@@ -643,11 +643,6 @@ void main(void)
643 total_active_file_hash = simple_hash("total_active_file");
644 total_unevictable_hash = simple_hash("total_unevictable");
645
646 - // cache functions
647 - (void)simple_hash2("hello world");
648 - (void)strcmp("1", "2");
649 - (void)strtoull("123", NULL, 0);
650 -
646 unsigned long i, c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7;
647 unsigned long max = 1000000;
648