perl plugin: Fix exporting notification meta data.
authorFlorian Forster <octo@collectd.org>
Fri, 1 Dec 2017 13:30:23 +0000 (14:30 +0100)
committerFlorian Forster <octo@collectd.org>
Fri, 1 Dec 2017 13:30:25 +0000 (14:30 +0100)
Previously, the while loop ensured that meta was NULL, causing the for
loop to never been executed. This introduces a new temporary variable to
avoid changing meta before the for loop.

CID: 37960

src/perl.c

index f58e02a..dcb553a 100644 (file)
@@ -496,7 +496,8 @@ static int av2data_set(pTHX_ AV *array, char *name, data_set_t *ds) {
  *   meta     => [ { name => <name>, value => <value> }, ... ]
  * }
  */
-static int av2notification_meta(pTHX_ AV *array, notification_meta_t **ret_meta) {
+static int av2notification_meta(pTHX_ AV *array,
+                                notification_meta_t **ret_meta) {
   notification_meta_t *tail = NULL;
 
   int len = av_len(array);
@@ -715,10 +716,8 @@ static int value_list2hv(pTHX_ value_list_t *vl, data_set_t *ds, HV *hash) {
 
 static int notification_meta2av(pTHX_ notification_meta_t *meta, AV *array) {
   int meta_num = 0;
-
-  while (meta) {
+  for (notification_meta_t *m = meta; m != NULL; m = m->next) {
     ++meta_num;
-    meta = meta->next;
   }
 
   av_extend(array, meta_num);