Merge branch 'collectd-5.5'
authorFlorian Forster <octo@collectd.org>
Wed, 17 Jun 2015 15:29:48 +0000 (17:29 +0200)
committerFlorian Forster <octo@collectd.org>
Wed, 17 Jun 2015 15:29:48 +0000 (17:29 +0200)
src/barometer.c
src/daemon/common.c
src/daemon/utils_cache.c
src/utils_db_query.c

index c1a7fa9..ee200b6 100644 (file)
@@ -581,7 +581,7 @@ static int MPL115_detect(void)
     return 0;
 }
 
-/** 
+/**
  * Read the MPL115 sensor conversion coefficients.
  *
  * These are (device specific) constants so we can read them just once.
@@ -590,18 +590,18 @@ static int MPL115_detect(void)
  */
 static int MPL115_read_coeffs(void)
 {
-    uint8_t mpl115_coeffs[MPL115_NUM_COEFFS]
+    uint8_t mpl115_coeffs[MPL115_NUM_COEFFS] = { 0 };
     int32_t res;
 
     int8_t  sia0MSB, sia0LSB, sib1MSB, sib1LSB, sib2MSB, sib2LSB;
     int8_t  sic12MSB, sic12LSB, sic11MSB, sic11LSB, sic22MSB, sic22LSB;
     int16_t sia0, sib1, sib2, sic12, sic11, sic22;
-      
+
     char errbuf[1024];
 
-    res = i2c_smbus_read_i2c_block_data(i2c_bus_fd, 
-                                        MPL115_ADDR_COEFFS, 
-                                        MPL115_NUM_COEFFS, 
+    res = i2c_smbus_read_i2c_block_data(i2c_bus_fd,
+                                        MPL115_ADDR_COEFFS,
+                                        STATIC_ARRAY_SIZE (mpl115_coeffs),
                                         mpl115_coeffs);
     if (res < 0)
     {
@@ -609,7 +609,7 @@ static int MPL115_read_coeffs(void)
                sstrerror (errno, errbuf, sizeof (errbuf)));
         return -1;
     }
-   
+
     /* Using perhaps less elegant/efficient code, but more readable. */
     /* a0: 16total 1sign 12int 4fract 0pad */
     sia0MSB = mpl115_coeffs[0];
@@ -618,7 +618,7 @@ static int MPL115_read_coeffs(void)
     sia0 += (int16_t) sia0LSB & 0x00FF;    /* Add LSB to 16bit number */
     mpl115_coeffA0 = (double) (sia0);
     mpl115_coeffA0 /= 8.0;                 /* 3 fract bits */
-    
+
     /* b1: 16total 1sign 2int 13fract 0pad */
     sib1MSB= mpl115_coeffs[2];
     sib1LSB= mpl115_coeffs[3];
@@ -626,7 +626,7 @@ static int MPL115_read_coeffs(void)
     sib1 += sib1LSB & 0x00FF;              /* Add LSB to 16bit number */
     mpl115_coeffB1 = (double) (sib1);
     mpl115_coeffB1 /= 8192.0;              /* 13 fract */
-    
+
     /* b2: 16total 1sign 1int 14fract 0pad */
     sib2MSB= mpl115_coeffs[4];
     sib2LSB= mpl115_coeffs[5];
@@ -663,11 +663,11 @@ static int MPL115_read_coeffs(void)
     mpl115_coeffC22 /= 33554432.0;          /* 10+15=25 fract */
 
     DEBUG("barometer: MPL115_read_coeffs: a0=%lf, b1=%lf, b2=%lf, c12=%lf, c11=%lf, c22=%lf",
-          mpl115_coeffA0, 
-          mpl115_coeffB1, 
-          mpl115_coeffB2, 
-          mpl115_coeffC12, 
-          mpl115_coeffC11, 
+          mpl115_coeffA0,
+          mpl115_coeffB1,
+          mpl115_coeffB2,
+          mpl115_coeffC12,
+          mpl115_coeffC11,
           mpl115_coeffC22);
     return 0;
 }
@@ -699,7 +699,7 @@ static void MPL115_convert_adc_to_real(double   adc_pressure,
 }
 
 
-/** 
+/**
  * Read sensor averegaed measurements
  *
  * @param pressure    averaged measured pressure
@@ -709,7 +709,7 @@ static void MPL115_convert_adc_to_real(double   adc_pressure,
  */
 static int MPL115_read_averaged(double * pressure, double * temperature)
 {
-    uint8_t mpl115_conv[MPL115_NUM_CONV]
+    uint8_t mpl115_conv[MPL115_NUM_CONV] = { 0 };
     int8_t  res;
     int     retries;
     int     conv_pressure;
@@ -720,7 +720,7 @@ static int MPL115_read_averaged(double * pressure, double * temperature)
 
     *pressure    = 0.0;
     *temperature = 0.0;
-   
+
     /* start conversion of both temp and presure */
     retries = MPL115_CONVERSION_RETRIES;
     while (retries>0)
@@ -756,8 +756,8 @@ static int MPL115_read_averaged(double * pressure, double * temperature)
     {
         res = i2c_smbus_read_i2c_block_data(i2c_bus_fd,
                                             MPL115_ADDR_CONV,
-                                            MPL115_NUM_CONV,
-                                            mpl115_conv); 
+                                            STATIC_ARRAY_SIZE (mpl115_conv),
+                                            mpl115_conv);
         if (res >= 0)
             break;
 
@@ -777,7 +777,7 @@ static int MPL115_read_averaged(double * pressure, double * temperature)
             return -1;
         }
     }
-    
+
     conv_pressure    = ((mpl115_conv[0] << 8) | mpl115_conv[1]) >> 6;
     conv_temperature = ((mpl115_conv[2] << 8) | mpl115_conv[3]) >> 6;
     DEBUG ("barometer: MPL115_read_averaged, raw pressure ADC value = %d, " \
@@ -796,7 +796,7 @@ static int MPL115_read_averaged(double * pressure, double * temperature)
            adc_temperature,
            *pressure,
            *temperature);
-    
+
     return 0;
 }
 
index e396b79..4720399 100644 (file)
@@ -312,44 +312,51 @@ int strsplit (char *string, char **fields, size_t size)
        return ((int) i);
 }
 
-int strjoin (char *dst, size_t dst_len,
+int strjoin (char *buffer, size_t buffer_size,
                char **fields, size_t fields_num,
                const char *sep)
 {
-       size_t field_len;
+       size_t avail;
+       char *ptr;
        size_t sep_len;
-       int i;
-
-       memset (dst, '\0', dst_len);
+       size_t i;
 
-       if (fields_num <= 0)
+       if ((buffer_size < 1) || (fields_num <= 0))
                return (-1);
 
+       memset (buffer, 0, buffer_size);
+       ptr = buffer;
+       avail = buffer_size - 1;
+
        sep_len = 0;
        if (sep != NULL)
                sep_len = strlen (sep);
 
-       for (i = 0; i < (int)fields_num; i++)
+       for (i = 0; i < fields_num; i++)
        {
+               size_t field_len;
+
                if ((i > 0) && (sep_len > 0))
                {
-                       if (dst_len <= sep_len)
+                       if (avail < sep_len)
                                return (-1);
 
-                       strncat (dst, sep, dst_len);
-                       dst_len -= sep_len;
+                       memcpy (ptr, sep, sep_len);
+                       ptr += sep_len;
+                       avail -= sep_len;
                }
 
                field_len = strlen (fields[i]);
-
-               if (dst_len <= field_len)
+               if (avail < field_len)
                        return (-1);
 
-               strncat (dst, fields[i], dst_len);
-               dst_len -= field_len;
+               memcpy (ptr, fields[i], field_len);
+               ptr += field_len;
+               avail -= field_len;
        }
 
-       return (strlen (dst));
+       assert (buffer[buffer_size - 1] == 0);
+       return (strlen (buffer));
 }
 
 int strsubstitute (char *str, char c_from, char c_to)
index fe22f21..46b6631 100644 (file)
@@ -322,7 +322,6 @@ int uc_check_timeout (void)
     if (status != 0)
     {
       ERROR ("uc_check_timeout: parse_identifier_vl (\"%s\") failed.", keys[i]);
-      cache_free (ce);
       continue;
     }
 
index 893d590..f29eabc 100644 (file)
@@ -1071,10 +1071,9 @@ udb_query_allocate_preparation_area (udb_query_t *q) /* {{{ */
   udb_result_preparation_area_t **next_r_area;
   udb_result_t *r;
 
-  q_area = (udb_query_preparation_area_t *)malloc (sizeof (*q_area));
+  q_area = malloc (sizeof (*q_area));
   if (q_area == NULL)
     return NULL;
-
   memset (q_area, 0, sizeof (*q_area));
 
   next_r_area = &q_area->result_prep_areas;
@@ -1082,14 +1081,18 @@ udb_query_allocate_preparation_area (udb_query_t *q) /* {{{ */
   {
     udb_result_preparation_area_t *r_area;
 
-    r_area = (udb_result_preparation_area_t *)malloc (sizeof (*r_area));
+    r_area = malloc (sizeof (*r_area));
     if (r_area == NULL)
     {
-      for (r_area = q_area->result_prep_areas;
-          r_area != NULL; r_area = r_area->next)
+      udb_result_preparation_area_t *a = q_area->result_prep_areas;
+
+      while (a != NULL)
       {
-        free (r_area);
+        udb_result_preparation_area_t *next = a->next;
+        sfree (a);
+        a = next;
       }
+
       free (q_area);
       return NULL;
     }