Merge branch 'collectd-4.6' into collectd-4.7
[collectd.git] / src / common.c
index ef80885..8f6cad2 100644 (file)
@@ -253,7 +253,7 @@ int strsplit (char *string, char **fields, size_t size)
                        break;
        }
 
-       return (i);
+       return ((int) i);
 }
 
 int strjoin (char *dst, size_t dst_len,
@@ -578,26 +578,26 @@ int check_create_dir (const char *file_orig)
 int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name)
 {
        char ident[128];
+
+       *ksp_ptr = NULL;
        
        if (kc == NULL)
                return (-1);
 
        ssnprintf (ident, sizeof (ident), "%s,%i,%s", module, instance, name);
 
+       *ksp_ptr = kstat_lookup (kc, module, instance, name);
        if (*ksp_ptr == NULL)
        {
-               if ((*ksp_ptr = kstat_lookup (kc, module, instance, name)) == NULL)
-               {
-                       ERROR ("Cound not find kstat %s", ident);
-                       return (-1);
-               }
+               ERROR ("get_kstat: Cound not find kstat %s", ident);
+               return (-1);
+       }
 
-               if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED)
-               {
-                       WARNING ("kstat %s has wrong type", ident);
-                       *ksp_ptr = NULL;
-                       return (-1);
-               }
+       if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED)
+       {
+               ERROR ("get_kstat: kstat %s has wrong type", ident);
+               *ksp_ptr = NULL;
+               return (-1);
        }
 
 #ifdef assert
@@ -607,13 +607,13 @@ int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name)
 
        if (kstat_read (kc, *ksp_ptr, NULL) == -1)
        {
-               WARNING ("kstat %s could not be read", ident);
+               ERROR ("get_kstat: kstat %s could not be read", ident);
                return (-1);
        }
 
        if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED)
        {
-               WARNING ("kstat %s has wrong type", ident);
+               ERROR ("get_kstat: kstat %s has wrong type", ident);
                return (-1);
        }
 
@@ -876,7 +876,11 @@ int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds)
                dummy = NULL;
 
                if (i >= vl->values_len)
+               {
+                       /* Make sure i is invalid. */
+                       i = vl->values_len + 1;
                        break;
+               }
 
                if (i == -1)
                {