From: Ruben Kerkhof Date: Sun, 16 Dec 2018 12:40:53 +0000 (+0100) Subject: Fix a couple of warnings in test suite X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=cc4ccdd5b5a991e3241f5107ec2161667a11b35d;p=collectd.git Fix a couple of warnings in test suite src/utils_vl_lookup_test.c: In function ‘checked_lookup_add’: src/utils_vl_lookup_test.c:91:3: warning: ‘strncpy’ specified bound 128 equals destination size [-Wstringop-truncation] strncpy(ident.host, host, sizeof(ident.host)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/utils_vl_lookup_test.c:92:3: warning: ‘strncpy’ specified bound 128 equals destination size [-Wstringop-truncation] strncpy(ident.plugin, plugin, sizeof(ident.plugin)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/utils_vl_lookup_test.c:93:3: warning: ‘strncpy’ specified bound 128 equals destination size [-Wstringop-truncation] strncpy(ident.plugin_instance, plugin_instance, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sizeof(ident.plugin_instance)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/utils_vl_lookup_test.c:95:3: warning: ‘strncpy’ specified bound 128 equals destination size [-Wstringop-truncation] strncpy(ident.type, type, sizeof(ident.type)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/utils_vl_lookup_test.c:96:3: warning: ‘strncpy’ specified bound 128 equals destination size [-Wstringop-truncation] strncpy(ident.type_instance, type_instance, sizeof(ident.type_instance)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/utils_vl_lookup_test.c: In function ‘checked_lookup_search’: src/utils_vl_lookup_test.c:113:3: warning: ‘strncpy’ specified bound 128 equals destination size [-Wstringop-truncation] strncpy(vl.host, host, sizeof(vl.host)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/utils_vl_lookup_test.c:114:3: warning: ‘strncpy’ specified bound 128 equals destination size [-Wstringop-truncation] strncpy(vl.plugin, plugin, sizeof(vl.plugin)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/utils_vl_lookup_test.c:115:3: warning: ‘strncpy’ specified bound 128 equals destination size [-Wstringop-truncation] strncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/utils_vl_lookup_test.c:116:3: warning: ‘strncpy’ specified bound 128 equals destination size [-Wstringop-truncation] strncpy(vl.type, type, sizeof(vl.type)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/utils_vl_lookup_test.c:117:3: warning: ‘strncpy’ specified bound 128 equals destination size [-Wstringop-truncation] strncpy(vl.type_instance, type_instance, sizeof(vl.type_instance)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CCLD test_utils_vl_lookup --- diff --git a/src/utils_vl_lookup_test.c b/src/utils_vl_lookup_test.c index 27bfddf0..274ddcd4 100644 --- a/src/utils_vl_lookup_test.c +++ b/src/utils_vl_lookup_test.c @@ -85,15 +85,15 @@ static int checked_lookup_add(lookup_t *obj, /* {{{ */ char const *plugin_instance, char const *type, char const *type_instance, unsigned int group_by) { - lookup_identifier_t ident; + lookup_identifier_t ident = {0}; void *user_class; - strncpy(ident.host, host, sizeof(ident.host)); - strncpy(ident.plugin, plugin, sizeof(ident.plugin)); + strncpy(ident.host, host, sizeof(ident.host) - 1); + strncpy(ident.plugin, plugin, sizeof(ident.plugin) - 1); strncpy(ident.plugin_instance, plugin_instance, - sizeof(ident.plugin_instance)); - strncpy(ident.type, type, sizeof(ident.type)); - strncpy(ident.type_instance, type_instance, sizeof(ident.type_instance)); + sizeof(ident.plugin_instance) - 1); + strncpy(ident.type, type, sizeof(ident.type) - 1); + strncpy(ident.type_instance, type_instance, sizeof(ident.type_instance) - 1); user_class = malloc(sizeof(ident)); memmove(user_class, &ident, sizeof(ident)); @@ -110,11 +110,11 @@ static int checked_lookup_search(lookup_t *obj, char const *host, value_list_t vl = VALUE_LIST_INIT; data_set_t const *ds = &ds_unknown; - strncpy(vl.host, host, sizeof(vl.host)); - strncpy(vl.plugin, plugin, sizeof(vl.plugin)); - strncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance)); - strncpy(vl.type, type, sizeof(vl.type)); - strncpy(vl.type_instance, type_instance, sizeof(vl.type_instance)); + strncpy(vl.host, host, sizeof(vl.host) - 1); + strncpy(vl.plugin, plugin, sizeof(vl.plugin) - 1); + strncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance) - 1); + strncpy(vl.type, type, sizeof(vl.type) - 1); + strncpy(vl.type_instance, type_instance, sizeof(vl.type_instance) - 1); if (strcmp(vl.type, "test") == 0) ds = &ds_test;