[OpenWrt-Devel] [PATCH uci 09/18] iron out all extra compiler warnings

Petr Štetiar ynezz at true.cz
Mon Nov 4 19:36:48 EST 2019


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 <ynezz at true.cz>
---
 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 386167db4cd1..97bdd29d3005 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 7333e48d51f7..bb102f52680a 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 78efbafe1c06..35d78f8d9ef2 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 b29c347b1d91..f4dce89b7c9f 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 63095b507d14..499c32ea17d4 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 b4f9518f5b5a..d5fd5c4f7143 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;

_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list