From c10379655f3ab88a1bfd657eeccc311c3c943f38 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Tue, 29 May 2018 15:57:00 +0200 Subject: [PATCH] virt plugin: fix a few sign compare warnings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit CC src/virt_la-virt.lo src/virt.c: In function ‘domain_state_submit_notif’: src/virt.c:1019:29: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare] if ((state < 0) || (state >= STATIC_ARRAY_SIZE(domain_states))) { ^~ src/virt.c:1027:31: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare] if ((reason < 0) || (reason >= STATIC_ARRAY_SIZE(domain_reasons[0]))) { ^~ src/virt.c: In function ‘fs_info_notify’: src/virt.c:1612:21: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare] for (int i = 0; i < fs_info->ndevAlias; ++i) { ^ src/virt.c:1587:25: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare] for (int _i = 0; _i < _size; ++_i) { \ ^ src/virt.c:1619:3: note: in expansion of macro ‘NM_ADD_STR_ITEMS’ NM_ADD_STR_ITEMS(fs_str_items, STATIC_ARRAY_SIZE(fs_str_items)); ^~~~~~~~~~~~~~~~ src/virt.c:1587:25: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare] for (int _i = 0; _i < _size; ++_i) { \ ^ src/virt.c:1622:3: note: in expansion of macro ‘NM_ADD_STR_ITEMS’ NM_ADD_STR_ITEMS(fs_dev_alias, fs_info->ndevAlias); ^~~~~~~~~~~~~~~~ CCLD virt.la --- src/virt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/virt.c b/src/virt.c index 9f87d2c2..c6280d12 100644 --- a/src/virt.c +++ b/src/virt.c @@ -1016,7 +1016,7 @@ static unsigned int parse_ex_stats_flags(char **exstats, int numexstats) { } static void domain_state_submit_notif(virDomainPtr dom, int state, int reason) { - if ((state < 0) || (state >= STATIC_ARRAY_SIZE(domain_states))) { + if ((state < 0) || ((size_t)state >= STATIC_ARRAY_SIZE(domain_states))) { ERROR(PLUGIN_NAME ": Array index out of bounds: state=%d", state); return; } @@ -1024,7 +1024,7 @@ static void domain_state_submit_notif(virDomainPtr dom, int state, int reason) { char msg[DATA_MAX_NAME_LEN]; const char *state_str = domain_states[state]; #ifdef HAVE_DOM_REASON - if ((reason < 0) || (reason >= STATIC_ARRAY_SIZE(domain_reasons[0]))) { + if ((reason < 0) || ((size_t)reason >= STATIC_ARRAY_SIZE(domain_reasons[0]))) { ERROR(PLUGIN_NAME ": Array index out of bounds: reason=%d", reason); return; } @@ -1584,7 +1584,7 @@ static int get_block_stats(struct block_device *block_dev) { #define NM_ADD_STR_ITEMS(_items, _size) \ do { \ - for (int _i = 0; _i < _size; ++_i) { \ + for (size_t _i = 0; _i < _size; ++_i) { \ DEBUG(PLUGIN_NAME \ " plugin: Adding notification metadata name=%s value=%s", \ _items[_i].name, _items[_i].value); \ @@ -1609,7 +1609,7 @@ static int fs_info_notify(virDomainPtr domain, virDomainFSInfoPtr fs_info) { {.name = "name", .value = fs_info->name}, {.name = "fstype", .value = fs_info->fstype}}; - for (int i = 0; i < fs_info->ndevAlias; ++i) { + for (size_t i = 0; i < fs_info->ndevAlias; ++i) { fs_dev_alias[i].name = "devAlias"; fs_dev_alias[i].value = fs_info->devAlias[i]; } -- 2.11.0