virt: Fetch block info stats from libvirt only if needed
[collectd.git] / src / utils_vl_lookup_test.c
index 058015e..1cb7b65 100644 (file)
@@ -29,8 +29,8 @@
 #include "testing.h"
 #include "utils_vl_lookup.h"
 
-static _Bool expect_new_obj = 0;
-static _Bool have_new_obj = 0;
+static bool expect_new_obj;
+static bool have_new_obj;
 
 static lookup_identifier_t last_class_ident;
 static lookup_identifier_t last_obj_ident;
@@ -75,7 +75,7 @@ static void *lookup_class_callback(data_set_t const *ds, value_list_t const *vl,
   strncpy(obj->type, vl->type, sizeof(obj->type));
   strncpy(obj->type_instance, vl->type_instance, sizeof(obj->type_instance));
 
-  have_new_obj = 1;
+  have_new_obj = true;
 
   return (void *)obj;
 }
@@ -85,15 +85,15 @@ static int checked_lookup_add(lookup_t *obj, /* {{{ */
                               char const *plugin_instance, char const *type,
                               char const *type_instance,
                               unsigned int group_by) {
-  lookup_identifier_t ident;
+  lookup_identifier_t ident = {{0}};
   void *user_class;
 
-  strncpy(ident.host, host, sizeof(ident.host));
-  strncpy(ident.plugin, plugin, sizeof(ident.plugin));
+  strncpy(ident.host, host, sizeof(ident.host) - 1);
+  strncpy(ident.plugin, plugin, sizeof(ident.plugin) - 1);
   strncpy(ident.plugin_instance, plugin_instance,
-          sizeof(ident.plugin_instance));
-  strncpy(ident.type, type, sizeof(ident.type));
-  strncpy(ident.type_instance, type_instance, sizeof(ident.type_instance));
+          sizeof(ident.plugin_instance) - 1);
+  strncpy(ident.type, type, sizeof(ident.type) - 1);
+  strncpy(ident.type_instance, type_instance, sizeof(ident.type_instance) - 1);
 
   user_class = malloc(sizeof(ident));
   memmove(user_class, &ident, sizeof(ident));
@@ -105,22 +105,22 @@ static int checked_lookup_add(lookup_t *obj, /* {{{ */
 static int checked_lookup_search(lookup_t *obj, char const *host,
                                  char const *plugin,
                                  char const *plugin_instance, char const *type,
-                                 char const *type_instance, _Bool expect_new) {
+                                 char const *type_instance, bool expect_new) {
   int status;
   value_list_t vl = VALUE_LIST_INIT;
   data_set_t const *ds = &ds_unknown;
 
-  strncpy(vl.host, host, sizeof(vl.host));
-  strncpy(vl.plugin, plugin, sizeof(vl.plugin));
-  strncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance));
-  strncpy(vl.type, type, sizeof(vl.type));
-  strncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
+  strncpy(vl.host, host, sizeof(vl.host) - 1);
+  strncpy(vl.plugin, plugin, sizeof(vl.plugin) - 1);
+  strncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance) - 1);
+  strncpy(vl.type, type, sizeof(vl.type) - 1);
+  strncpy(vl.type_instance, type_instance, sizeof(vl.type_instance) - 1);
 
   if (strcmp(vl.type, "test") == 0)
     ds = &ds_test;
 
   expect_new_obj = expect_new;
-  have_new_obj = 0;
+  have_new_obj = false;
 
   status = lookup_search(obj, ds, &vl);
   return status;