From d2e026a33df81f116ceb2567056346f38d139706 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20=C5=A0tetiar?= Date: Wed, 11 Dec 2019 10:36:36 +0100 Subject: [PATCH] iron out all extra compiler warnings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit clang-9 on x86/64 has reported following warnings/errors: libubus-acl.c:123:2: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] libubus-io.c:108:18: error: comparison of integers of different signs: 'int' and 'size_t' (aka 'unsigned long') [-Werror,-Wsign-compare] libubus-io.c:395:56: error: comparison of integers of different signs: 'ssize_t' (aka 'long') and 'size_t' (aka 'unsigned long') [-Werror,-Wsign-compare] libubus-req.c:441:4: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] ubusd_acl.c:119:18: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] ubusd_acl.c:152:5: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] ubusd_acl.c:348:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] ubusd_acl.c:352:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] ubusd_acl.c:357:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] ubusd_acl.c:362:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] ubusd_acl.c:367:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] ubusd_acl.c:447:16: error: comparison of integers of different signs: 'int' and '__size_t' (aka 'unsigned long') [-Werror,-Wsign-compare] ubusd_acl.c:502:18: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] ubusd.c:123:13: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] ubusd.c:170:15: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] ubusd.c:262:43: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] ubusd.c:287:30: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] ubusd_event.c:170:18: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] ubusd_obj.c:71:2: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] Signed-off-by: Petr Å tetiar --- cli.c | 11 ++++++----- examples/server.c | 7 ++++--- libubus-acl.c | 2 +- libubus-io.c | 6 +++--- libubus-req.c | 3 ++- lua/ubus.c | 4 ++-- ubusd.c | 14 +++++++------- ubusd_acl.c | 10 +++++----- ubusd_event.c | 2 +- ubusd_obj.c | 2 +- 10 files changed, 32 insertions(+), 29 deletions(-) diff --git a/cli.c b/cli.c index 19ccbb5..421f244 100644 --- a/cli.c +++ b/cli.c @@ -47,7 +47,7 @@ static const char *format_type(void *priv, struct blob_attr *attr) [BLOBMSG_TYPE_TABLE] = "\"Table\"", }; const char *type = NULL; - int typeid; + size_t typeid; if (blob_id(attr) != BLOBMSG_TYPE_INT32) return NULL; @@ -65,7 +65,7 @@ static void receive_list_result(struct ubus_context *ctx, struct ubus_object_dat { struct blob_attr *cur; char *s; - int rem; + size_t rem; if (simple_output || !verbose) { printf("%s\n", obj->path); @@ -520,7 +520,7 @@ static int ubus_cli_monitor(struct ubus_context *ctx, int argc, char **argv) static int add_monitor_type(const char *type) { - int i; + size_t i; for (i = 0; i < ARRAY_SIZE(monitor_types); i++) { if (!monitor_types[i] || strcmp(monitor_types[i], type) != 0) @@ -575,9 +575,10 @@ int main(int argc, char **argv) { const char *progname, *ubus_socket = NULL; struct ubus_context *ctx; - char *cmd; int ret = 0; - int i, ch; + char *cmd; + size_t i; + int ch; progname = argv[0]; diff --git a/examples/server.c b/examples/server.c index e0cde0b..004eaf3 100644 --- a/examples/server.c +++ b/examples/server.c @@ -84,7 +84,7 @@ static int test_hello(struct ubus_context *ctx, struct ubus_object *obj, { struct hello_request *hreq; struct blob_attr *tb[__HELLO_MAX]; - const char *format = "%s received a message: %s"; + const char format[] = "%s received a message: %s"; const char *msgstr = "(unknown)"; blobmsg_parse(hello_policy, ARRAY_SIZE(hello_policy), tb, blob_data(msg), blob_len(msg)); @@ -92,11 +92,12 @@ static int test_hello(struct ubus_context *ctx, struct ubus_object *obj, if (tb[HELLO_MSG]) msgstr = blobmsg_data(tb[HELLO_MSG]); - hreq = calloc(1, sizeof(*hreq) + strlen(format) + strlen(obj->name) + strlen(msgstr) + 1); + size_t len = sizeof(*hreq) + sizeof(format) + strlen(obj->name) + strlen(msgstr) + 1; + hreq = calloc(1, len); if (!hreq) return UBUS_STATUS_UNKNOWN_ERROR; - sprintf(hreq->data, format, obj->name, msgstr); + snprintf(hreq->data, len, format, obj->name, msgstr); ubus_defer_request(ctx, req, &hreq->req); hreq->timeout.cb = test_hello_reply; uloop_timeout_set(&hreq->timeout, 1000); diff --git a/libubus-acl.c b/libubus-acl.c index 0274520..aab6629 100644 --- a/libubus-acl.c +++ b/libubus-acl.c @@ -102,7 +102,7 @@ static void acl_recv_cb(struct ubus_request *req, { struct blob_attr *tb[__ACL_POLICY_MAX]; struct blob_attr *cur; - int rem; + size_t rem; if (acl_blob) { struct acl_object *p, *q; diff --git a/libubus-io.c b/libubus-io.c index cdd1e6e..120fb60 100644 --- a/libubus-io.c +++ b/libubus-io.c @@ -78,7 +78,7 @@ static int writev_retry(int fd, struct iovec *iov, int iov_len, int sock_fd) int len = 0; do { - int cur_len; + ssize_t cur_len; if (sock_fd < 0) { msghdr.msg_control = NULL; @@ -105,7 +105,7 @@ static int writev_retry(int fd, struct iovec *iov, int iov_len, int sock_fd) sock_fd = -1; len += cur_len; - while (cur_len >= iov->iov_len) { + while (cur_len >= (ssize_t) iov->iov_len) { cur_len -= iov->iov_len; iov_len--; iov++; @@ -392,7 +392,7 @@ int ubus_reconnect(struct ubus_context *ctx, const char *path) goto out_close; memcpy(buf, &hdr.data, sizeof(hdr.data)); - if (read(ctx->sock.fd, blob_data(buf), blob_len(buf)) != blob_len(buf)) + if (read(ctx->sock.fd, blob_data(buf), blob_len(buf)) != (ssize_t) blob_len(buf)) goto out_free; ctx->local_id = hdr.hdr.peer; diff --git a/libubus-req.c b/libubus-req.c index 74446f3..97785a1 100644 --- a/libubus-req.c +++ b/libubus-req.c @@ -428,7 +428,8 @@ static void ubus_process_notify_status(struct ubus_request *req, int id, struct struct ubus_notify_request *nreq; struct blob_attr **tb; struct blob_attr *cur; - int rem, idx = 1; + size_t rem; + int idx = 1; int ret = 0; nreq = container_of(req, struct ubus_notify_request, req); diff --git a/lua/ubus.c b/lua/ubus.c index 4da3c80..6fbbc06 100644 --- a/lua/ubus.c +++ b/lua/ubus.c @@ -52,11 +52,11 @@ static int ubus_lua_parse_blob(lua_State *L, struct blob_attr *attr, bool table); static int -ubus_lua_parse_blob_array(lua_State *L, struct blob_attr *attr, int len, bool table) +ubus_lua_parse_blob_array(lua_State *L, struct blob_attr *attr, size_t len, bool table) { int rv; int idx = 1; - int rem = len; + size_t rem = len; struct blob_attr *pos; lua_newtable(L); diff --git a/ubusd.c b/ubusd.c index d6a72e7..c020ff4 100644 --- a/ubusd.c +++ b/ubusd.c @@ -92,7 +92,7 @@ void ubus_msg_free(struct ubus_msg_buf *ub) } } -static int ubus_msg_writev(int fd, struct ubus_msg_buf *ub, int offset) +static ssize_t ubus_msg_writev(int fd, struct ubus_msg_buf *ub, size_t offset) { static struct iovec iov[2]; static struct { @@ -112,7 +112,7 @@ static int ubus_msg_writev(int fd, struct ubus_msg_buf *ub, int offset) .msg_controllen = sizeof(fd_buf), }; struct ubus_msghdr hdr; - int ret; + ssize_t ret; fd_buf.fd = ub->fd; if (ub->fd < 0 || offset) { @@ -156,7 +156,7 @@ static void ubus_msg_enqueue(struct ubus_client *cl, struct ubus_msg_buf *ub) /* takes the msgbuf reference */ void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub) { - int written; + ssize_t written; if (ub->hdr.type != UBUS_MSG_MONITOR) ubusd_monitor_message(cl, ub, true); @@ -167,7 +167,7 @@ void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub) if (written < 0) written = 0; - if (written >= ub->len + sizeof(ub->hdr)) + if (written >= (ssize_t) (ub->len + sizeof(ub->hdr))) return; cl->txq_ofs = written; @@ -232,7 +232,7 @@ static void client_cb(struct uloop_fd *sock, unsigned int events) /* first try to tx more pending data */ while ((ub = ubus_msg_head(cl))) { - int written; + ssize_t written; written = ubus_msg_writev(sock->fd, ub, cl->txq_ofs); if (written < 0) { @@ -259,7 +259,7 @@ static void client_cb(struct uloop_fd *sock, unsigned int events) uloop_fd_add(sock, ULOOP_READ | ULOOP_EDGE_TRIGGER); retry: - if (!sock->eof && cl->pending_msg_offset < sizeof(cl->hdrbuf)) { + if (!sock->eof && cl->pending_msg_offset < (int) sizeof(cl->hdrbuf)) { int offset = cl->pending_msg_offset; int bytes; @@ -284,7 +284,7 @@ retry: cl->pending_msg_fd = fd_buf.fd; cl->pending_msg_offset += bytes; - if (cl->pending_msg_offset < sizeof(cl->hdrbuf)) + if (cl->pending_msg_offset < (int) sizeof(cl->hdrbuf)) goto out; if (blob_pad_len(&cl->hdrbuf.data) > UBUS_MAX_MSGLEN) diff --git a/ubusd_acl.c b/ubusd_acl.c index 6257f81..f19df9a 100644 --- a/ubusd_acl.c +++ b/ubusd_acl.c @@ -116,7 +116,7 @@ ubusd_acl_check(struct ubus_client *cl, const char *obj, if (!acl->partial) continue; - if (match_len != strlen(key)) + if (match_len != (int) strlen(key)) continue; } @@ -147,7 +147,7 @@ ubusd_acl_check(struct ubus_client *cl, const char *obj, case UBUS_ACL_ACCESS: if (acl->methods) { struct blob_attr *cur; - int rem; + size_t rem; blobmsg_for_each_attr(cur, acl->methods, rem) if (blobmsg_type(cur) == BLOBMSG_TYPE_STRING) @@ -332,7 +332,7 @@ static void ubusd_acl_file_add(struct ubusd_acl_file *file) { struct blob_attr *tb[__ACL_MAX], *cur; - int rem; + size_t rem; blobmsg_parse(acl_policy, __ACL_MAX, tb, blob_data(file->blob), blob_len(file->blob)); @@ -435,7 +435,7 @@ ubusd_acl_load(void) { struct stat st; glob_t gl; - int j; + size_t j; const char *suffix = "/*.json"; char *path = alloca(strlen(ubusd_acl_dir) + strlen(suffix) + 1); @@ -499,7 +499,7 @@ ubusd_reply_add(struct ubus_object *obj) if (!acl->partial) continue; - if (match_len != strlen(key)) + if (match_len != (int) strlen(key)) continue; } diff --git a/ubusd_event.c b/ubusd_event.c index 712e704..d36bcb7 100644 --- a/ubusd_event.c +++ b/ubusd_event.c @@ -167,7 +167,7 @@ int ubusd_send_event(struct ubus_client *cl, const char *id, if (!ev->partial) continue; - if (match_len != strlen(key)) + if (match_len != (int) strlen(key)) continue; } diff --git a/ubusd_obj.c b/ubusd_obj.c index 0831473..0c9cb9a 100644 --- a/ubusd_obj.c +++ b/ubusd_obj.c @@ -55,7 +55,7 @@ static struct ubus_object_type *ubus_create_obj_type(struct blob_attr *sig) { struct ubus_object_type *type; struct blob_attr *pos; - int rem; + size_t rem; type = calloc(1, sizeof(*type)); if (!type) -- 2.25.1