From af59f86a0db914db60243563956f20e2c0850213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0tetiar?= Date: Mon, 4 Nov 2019 18:21:44 +0100 Subject: iron out all extra compiler warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc 9.1 on x86/64 has reported following issues: list.c:140:11: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] file.c:572:51: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] file.c:850:15: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] file.c:865:15: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] delta.c:199:6: error: this statement may fall through [-Werror=implicit-fallthrough=] parse.c:80:12: error: this statement may fall through [-Werror=implicit-fallthrough=] parse.c:81:12: error: this statement may fall through [-Werror=implicit-fallthrough=] file.c:572:51: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] file.c:850:15: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] file.c:865:15: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] delta.c:199:6: error: this statement may fall through [-Werror=implicit-fallthrough=] parse.c:80:12: error: this statement may fall through [-Werror=implicit-fallthrough=] parse.c:81:12: error: this statement may fall through [-Werror=implicit-fallthrough=] ucimap.c:146:16: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] ucimap.c:151:17: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] ucimap.c:243:34: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] ucimap.c:247:9: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] ucimap.c:254:39: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] ucimap.c:258:9: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] ucimap.c:285:34: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] ucimap.c:363:17: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] ucimap.c:563:12: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] ucimap.c:753:18: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] ucimap.c:879:17: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] Signed-off-by: Petr Štetiar --- delta.c | 1 + file.c | 5 +++-- list.c | 4 ++-- lua/uci.c | 3 ++- parse.c | 2 ++ ucimap.c | 15 ++++++++------- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/delta.c b/delta.c index 52ebe3b..a131e3a 100644 --- a/delta.c +++ b/delta.c @@ -198,6 +198,7 @@ static inline int uci_parse_delta_tuple(struct uci_context *ctx, struct uci_ptr case UCI_CMD_LIST_ADD: if (!ptr->option) goto error; + /* fall through */ case UCI_CMD_LIST_DEL: if (!ptr->option) goto error; diff --git a/file.c b/file.c index 321b66b..f5032bd 100644 --- a/file.c +++ b/file.c @@ -569,7 +569,7 @@ static const char *uci_escape(struct uci_context *ctx, const char *str) len = end - str; /* make sure that we have enough room in the buffer */ - while (ofs + len + sizeof(UCI_QUOTE_ESCAPE) + 1 > ctx->bufsz) { + while (ofs + len + (int) sizeof(UCI_QUOTE_ESCAPE) + 1 > ctx->bufsz) { ctx->bufsz *= 2; ctx->buf = uci_realloc(ctx, ctx->buf, ctx->bufsz); } @@ -834,7 +834,8 @@ static char **uci_list_config_files(struct uci_context *ctx) { char **configs; glob_t globbuf; - int size, i, j, skipped; + int size, j, skipped; + size_t i; char *buf; char *dir; diff --git a/list.c b/list.c index 41a8702..24ed2ee 100644 --- a/list.c +++ b/list.c @@ -137,7 +137,7 @@ static unsigned int djbhash(unsigned int hash, char *str) int i; /* initial value */ - if (hash == ~0) + if (hash == ~0U) hash = 5381; for(i = 0; i < len; i++) { @@ -149,7 +149,7 @@ static unsigned int djbhash(unsigned int hash, char *str) /* fix up an unnamed section, e.g. after adding options to it */ static void uci_fixup_section(struct uci_context *ctx, struct uci_section *s) { - unsigned int hash = ~0; + unsigned int hash = ~0U; struct uci_element *e; char buf[16]; diff --git a/lua/uci.c b/lua/uci.c index b29c347..f4dce89 100644 --- a/lua/uci.c +++ b/lua/uci.c @@ -605,7 +605,8 @@ uci_lua_set(lua_State *L) int err = UCI_ERR_MEM; char *s = NULL; const char *v; - int i, nargs, offset = 0; + unsigned int i; + int nargs, offset = 0; ctx = find_context(L, &offset); nargs = lua_gettop(L); diff --git a/parse.c b/parse.c index 63095b5..499c32e 100644 --- a/parse.c +++ b/parse.c @@ -78,7 +78,9 @@ static uint32_t hash_murmur2(uint32_t h, const void * key, int len) switch(len) { case 3: h ^= data[2] << 16; + /* fall through */ case 2: h ^= data[1] << 8; + /* fall through */ case 1: h ^= data[0]; h *= m; }; diff --git a/ucimap.c b/ucimap.c index b4f9518..d5fd5c4 100644 --- a/ucimap.c +++ b/ucimap.c @@ -134,7 +134,7 @@ void ucimap_free_section(struct uci_map *map, struct ucimap_section_data *sd) { void *section; - int i; + unsigned int i; section = ucimap_section_ptr(sd); if (sd->ref) @@ -234,7 +234,7 @@ ucimap_free_item(struct ucimap_section_data *sd, void *item) struct ucimap_alloc_custom *ac; struct ucimap_alloc *a; void *ptr = *((void **) item); - int i; + unsigned int i; if (!ptr) return; @@ -270,7 +270,8 @@ ucimap_resize_list(struct ucimap_section_data *sd, struct ucimap_list **list, in { struct ucimap_list *new; struct ucimap_alloc *a; - int i, offset = 0; + unsigned int i; + int offset = 0; int size = sizeof(struct ucimap_list) + items * sizeof(union ucimap_data); if (!*list) { @@ -360,7 +361,7 @@ ucimap_add_value(union ucimap_data *data, struct uci_optmap *om, struct ucimap_s switch(om->type & UCIMAP_SUBTYPE) { case UCIMAP_STRING: if ((om->data.s.maxlen > 0) && - (strlen(str) > om->data.s.maxlen)) + (strlen(str) > (unsigned) om->data.s.maxlen)) return; s = strdup(str); @@ -532,7 +533,7 @@ ucimap_get_type_name(int type) static bool ucimap_check_optmap_type(struct uci_sectionmap *sm, struct uci_optmap *om) { - unsigned int type; + int type; if (unlikely(sm->type_name != om->type_name) && unlikely(strcmp(sm->type_name, om->type_name) != 0)) { @@ -746,7 +747,7 @@ ucimap_set_changed(struct ucimap_section_data *sd, void *field) void *section = ucimap_section_ptr(sd); struct uci_sectionmap *sm = sd->sm; struct uci_optmap *om; - int ofs = (char *)field - (char *)section; + unsigned int ofs = (char *)field - (char *)section; int i = 0; ucimap_foreach_option(sm, om) { @@ -868,7 +869,7 @@ ucimap_parse(struct uci_map *map, struct uci_package *pkg) struct uci_element *e; struct ucimap_section_data *sd, **sd_tail; struct ucimap_fixup *f; - int i; + unsigned int i; sd_tail = map->sdata_tail; map->parsed = false; -- cgit v1.2.1