{GPL, other}: Relicense to MIT license.
[collectd.git] / src / utils_ignorelist.c
index d2546aa..0ad252b 100644 (file)
@@ -1,6 +1,7 @@
 /**
  * collectd - src/utils_ignorelist.c
  * Copyright (C) 2006 Lubos Stanek <lubek at users.sourceforge.net>
+ * Copyright (C) 2008 Florian Forster <octo at collectd.org>
  *
  * This program is free software; you can redistribute it and/
  * or modify it under the terms of the GNU General Public Li-
@@ -19,6 +20,7 @@
  *
  * Authors:
  *   Lubos Stanek <lubek at users.sourceforge.net>
+ *   Florian Forster <octo at collectd.org>
  **/
 /**
  * ignorelist handles plugin's list of configured collectable
@@ -217,10 +219,6 @@ ignorelist_t *ignorelist_create (int invert)
 
        /* smalloc exits if it failes */
        il = (ignorelist_t *) smalloc (sizeof (ignorelist_t));
-       DEBUG("Ignorelist created 0x%p, default is %s",
-                       (void *) il,
-                       invert ? "collect" : "ignore");
-
        memset (il, '\0', sizeof (ignorelist_t));
 
        /*
@@ -240,8 +238,6 @@ void ignorelist_free (ignorelist_t *il)
        ignorelist_item_t *this;
        ignorelist_item_t *next;
 
-       DEBUG ("(il = 0x%p)", (void *) il);
-
        if (il == NULL)
                return;
 
@@ -310,11 +306,12 @@ int ignorelist_add (ignorelist_t *il, const char *entry)
        if ((entry_len > 2) && (entry[0] == '/') && entry[entry_len - 1] == '/')
        {
                char *entry_copy;
+               size_t entry_copy_size;
 
                /* We need to copy `entry' since it's const */
-               entry_copy = smalloc (entry_len);
-               memset (entry_copy, '\0', entry_len);
-               strncpy (entry_copy, entry + 1, entry_len - 2);
+               entry_copy_size = entry_len - 1;
+               entry_copy = smalloc (entry_copy_size);
+               sstrncpy (entry_copy, entry + 1, entry_copy_size);
 
                DEBUG("I'm about to add regex entry: %s", entry_copy);
                ret = ignorelist_append_regex(il, entry_copy);
@@ -338,10 +335,8 @@ int ignorelist_match (ignorelist_t *il, const char *entry)
 {
        ignorelist_item_t *traverse;
 
-       assert (il != NULL);
-
        /* if no entries, collect all */
-       if (il->head == NULL)
+       if ((il == NULL) || (il->head == NULL))
                return (0);
 
        if ((entry == NULL) || (strlen (entry) == 0))