X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Futils_ignorelist.c;h=60a8c2733f3786703c9d52ee297462af86a4582b;hb=749b03b3fc459895b7415c7c13753066bf0af55b;hp=a8ca7dbb7f3aecbb2c6ea90519c2583aae0c30f5;hpb=584f57cc8cfb14cbcc45714db5dc87304ccb2a0e;p=collectd.git diff --git a/src/daemon/utils_ignorelist.c b/src/daemon/utils_ignorelist.c index a8ca7dbb..60a8c273 100644 --- a/src/daemon/utils_ignorelist.c +++ b/src/daemon/utils_ignorelist.c @@ -98,7 +98,7 @@ static int ignorelist_append_regex(ignorelist_t *il, const char *re_str) re = malloc (sizeof (*re)); if (re == NULL) { - ERROR ("utils_ignorelist: malloc failed"); + ERROR ("ignorelist_append_regex: malloc failed."); return (ENOMEM); } memset (re, 0, sizeof (*re)); @@ -106,10 +106,10 @@ static int ignorelist_append_regex(ignorelist_t *il, const char *re_str) status = regcomp (re, re_str, REG_EXTENDED); if (status != 0) { - char errbuf[1024] = ""; - regerror (status, re, errbuf, sizeof (errbuf)); + char errbuf[1024]; + (void) regerror (status, re, errbuf, sizeof (errbuf)); ERROR ("utils_ignorelist: regcomp failed: %s", errbuf); - regfree (re); + ERROR ("ignorelist_append_regex: Compiling regular expression \"%s\" failed: %s", re_str, errbuf); sfree (re); return (status); } @@ -117,7 +117,7 @@ static int ignorelist_append_regex(ignorelist_t *il, const char *re_str) entry = malloc (sizeof (*entry)); if (entry == NULL) { - ERROR ("utils_ignorelist: malloc failed"); + ERROR ("ignorelist_append_regex: malloc failed."); regfree (re); sfree (re); return (ENOMEM); @@ -195,9 +195,10 @@ ignorelist_t *ignorelist_create (int invert) { ignorelist_t *il; - /* smalloc exits if it failes */ - il = (ignorelist_t *) smalloc (sizeof (ignorelist_t)); - memset (il, '\0', sizeof (ignorelist_t)); + il = malloc (sizeof (*il)); + if (il == NULL) + return NULL; + memset (il, 0, sizeof (*il)); /* * ->ignore == 0 => collect @@ -262,7 +263,7 @@ void ignorelist_set_invert (ignorelist_t *il, int invert) */ int ignorelist_add (ignorelist_t *il, const char *entry) { - size_t entry_len; + size_t len; if (il == NULL) { @@ -270,10 +271,10 @@ int ignorelist_add (ignorelist_t *il, const char *entry) return (1); } - entry_len = strlen (entry); + len = strlen (entry); /* append nothing */ - if (entry_len == 0) + if (len == 0) { DEBUG("not appending: empty entry"); return (1); @@ -281,19 +282,21 @@ int ignorelist_add (ignorelist_t *il, const char *entry) #if HAVE_REGEX_H /* regex string is enclosed in "/.../" */ - if ((entry_len > 2) && (entry[0] == '/') && entry[entry_len - 1] == '/') + if ((len > 2) && (entry[0] == '/') && entry[len - 1] == '/') { - char *entry_copy; - size_t entry_copy_size; + char *copy; int status; - /* We need to copy `entry' since it's const */ - entry_copy_size = entry_len - 1; - entry_copy = smalloc (entry_copy_size); - sstrncpy (entry_copy, entry + 1, entry_copy_size); + /* skip leading slash */ + copy = strdup (entry + 1); + if (copy == NULL) + return ENOMEM; + + /* trim trailing slash */ + copy[strlen (copy) - 1] = 0; - status = ignorelist_append_regex(il, entry_copy); - sfree (entry_copy); + status = ignorelist_append_regex (il, copy); + sfree (copy); return status; } #endif