ceph plugin: fix scan-build warnings
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Wed, 30 May 2018 13:08:15 +0000 (15:08 +0200)
committerFlorian Forster <octo@collectd.org>
Mon, 8 Oct 2018 20:10:13 +0000 (22:10 +0200)
src/ceph.c:284:8: warning: Null pointer argument in call to string comparison function
  (strcmp("filestore", state->stack[state->depth - 2]) == 0) &&
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/string2.h:817:8: note: expanded from macro 'strcmp'
: __builtin_strcmp (s1, s2)))); })
  ^~~~~~~~~~~~~~~~~~~~~~~~~
src/ceph.c:285:8: warning: Null pointer argument in call to string comparison function
  (strcmp("journal_wr_bytes", state->stack[state->depth - 1]) == 0) &&
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/string2.h:817:8: note: expanded from macro 'strcmp'
: __builtin_strcmp (s1, s2)))); })
  ^~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.

Cherry-pick for collectd-5.8.

src/ceph.c

index 73140a5..5ea9049 100644 (file)
@@ -281,7 +281,9 @@ static int ceph_cb_number(void *ctx, const char *number_val,
    * "rate", use the "sum" in the pair and assign that to the derive
    * value. */
   if (convert_special_metrics && (state->depth > 2) &&
+      state->stack[state->depth - 2] &&
       (strcmp("filestore", state->stack[state->depth - 2]) == 0) &&
+      state->stack[state->depth - 1] &&
       (strcmp("journal_wr_bytes", state->stack[state->depth - 1]) == 0) &&
       (strcmp("avgcount", state->key) == 0)) {
     DEBUG("ceph plugin: Skipping avgcount for filestore.JournalWrBytes");