From 7f4143effc63ffbfa7593280822e4ca2cd7e0c09 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 18 Jun 2015 13:36:02 +0200 Subject: [PATCH] Fix "Argument with 'nonnull' attribute passed null" warnings. --- src/collectd.c | 3 ++- src/configfile.c | 10 +++++++--- src/df.c | 15 ++++++++------- src/libvirt.c | 6 ++++++ src/table.c | 3 ++- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/collectd.c b/src/collectd.c index d2597530..6815cccf 100644 --- a/src/collectd.c +++ b/src/collectd.c @@ -384,8 +384,9 @@ static int pidfile_create (void) static int pidfile_remove (void) { const char *file = global_option_get ("PIDFile"); + if (file == NULL) + return 0; - DEBUG ("unlink (%s)", (file != NULL) ? file : ""); return (unlink (file)); } /* static int pidfile_remove (const char *file) */ #endif /* COLLECT_DAEMON */ diff --git a/src/configfile.c b/src/configfile.c index a337c6f5..c389ad16 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -150,9 +150,12 @@ static int cf_dispatch (const char *type, const char *orig_key, int ret; int i; + if (orig_key == NULL) + return (EINVAL); + DEBUG ("type = %s, key = %s, value = %s", ESCAPE_NULL(type), - ESCAPE_NULL(orig_key), + orig_key, ESCAPE_NULL(orig_value)); if ((cf_cb = cf_search (type)) == NULL) @@ -193,8 +196,6 @@ static int cf_dispatch (const char *type, const char *orig_key, free (key); free (value); - DEBUG ("cf_dispatch: return (%i)", ret); - return (ret); } /* int cf_dispatch */ @@ -741,6 +742,9 @@ static oconfig_item_t *cf_read_dir (const char *dir, filenames[filenames_num - 1] = sstrdup (name); } + if (filenames == NULL) + return (root); + qsort ((void *) filenames, filenames_num, sizeof (*filenames), cf_compare_string); diff --git a/src/df.c b/src/df.c index 3d5a402c..ae09e6b7 100644 --- a/src/df.c +++ b/src/df.c @@ -208,10 +208,11 @@ static int df_read (void) uint64_t blk_reserved; uint64_t blk_used; - if (ignorelist_match (il_device, - (mnt_ptr->spec_device != NULL) - ? mnt_ptr->spec_device - : mnt_ptr->device)) + char const *dev = (mnt_ptr->spec_device != NULL) + ? mnt_ptr->spec_device + : mnt_ptr->device; + + if (ignorelist_match (il_device, dev)) continue; if (ignorelist_match (il_mountpoint, mnt_ptr->dir)) continue; @@ -234,10 +235,10 @@ static int df_read (void) if (by_device) { /* eg, /dev/hda1 -- strip off the "/dev/" */ - if (strncmp (mnt_ptr->spec_device, "/dev/", strlen ("/dev/")) == 0) - sstrncpy (disk_name, mnt_ptr->spec_device + strlen ("/dev/"), sizeof (disk_name)); + if (strncmp (dev, "/dev/", strlen ("/dev/")) == 0) + sstrncpy (disk_name, dev + strlen ("/dev/"), sizeof (disk_name)); else - sstrncpy (disk_name, mnt_ptr->spec_device, sizeof (disk_name)); + sstrncpy (disk_name, dev, sizeof (disk_name)); if (strlen(disk_name) < 1) { diff --git a/src/libvirt.c b/src/libvirt.c index 87b71e69..6a397db3 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -798,6 +798,9 @@ add_interface_device (virDomainPtr dom, const char *path, const char *address, u int new_size = sizeof (interface_devices[0]) * (nr_interface_devices+1); char *path_copy, *address_copy, number_string[15]; + if ((path == NULL) || (address == NULL)) + return EINVAL; + path_copy = strdup (path); if (!path_copy) return -1; @@ -833,6 +836,9 @@ ignore_device_match (ignorelist_t *il, const char *domname, const char *devpath) char *name; int n, r; + if ((domname == NULL) || (devpath == NULL)) + return 0; + n = sizeof (char) * (strlen (domname) + strlen (devpath) + 2); name = malloc (n); if (name == NULL) { diff --git a/src/table.c b/src/table.c index 9641c759..a3bacc7a 100644 --- a/src/table.c +++ b/src/table.c @@ -278,8 +278,9 @@ static int tbl_config_table (oconfig_item_t *ci) if (NULL == tbl->sep) { log_err ("Table \"%s\" does not specify any separator.", tbl->file); status = 1; + } else { + strunescape (tbl->sep, strlen (tbl->sep) + 1); } - strunescape (tbl->sep, strlen (tbl->sep) + 1); if (NULL == tbl->instance) { tbl->instance = sstrdup (tbl->file); -- 2.11.0