Merge pull request #2722 from elfiesmelfie/increase_buffer
[collectd.git] / src / varnish.c
index ebc8e7a..08260dc 100644 (file)
@@ -152,30 +152,25 @@ static int varnish_monitor(void *priv,
   conf = priv;
 
 #if HAVE_VARNISH_V5
-  char namebuff[100];
-  char *c;
+  char namebuff[DATA_MAX_NAME_LEN];
 
-  c = rindex(pt->name, '.');
-  strcpy(namebuff, c + 1);
+  char const *c = strrchr(pt->name, '.');
+  if (c == NULL) {
+    return EINVAL;
+  }
+  sstrncpy(namebuff, c + 1, sizeof(namebuff));
   name = namebuff;
 
 #elif HAVE_VARNISH_V4
-  const char *class;
-
-  class = pt->section->fantom->type;
-  name = pt->desc->name;
-
-  if (strcmp(class, "MAIN") != 0)
+  if (strcmp(pt->section->fantom->type, "MAIN") != 0)
     return 0;
 
+  name = pt->desc->name;
 #elif HAVE_VARNISH_V3
-  const char *class;
+  if (strcmp(pt->class, "") != 0)
+    return 0;
 
-  class = pt->class;
   name = pt->name;
-
-  if (strcmp(class, "") != 0)
-    return 0;
 #endif
 
   val = *(const volatile uint64_t *)pt->ptr;