From patchwork Thu Dec 19 22:11:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1213782 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="qnwj7fKh"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47f5jF3pK2z9sPL for ; Fri, 20 Dec 2019 09:12:49 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jjxsLHgtuxSlsnpHM22w4GMBOAnzPOo1+KWYsFoom+U=; b=qnwj7fKhlK0xJp AE5kSmQBuW2Gve9N2vnypxg22DVBApssz0BVrAHaoFXquofCszruQouBTIkGWWnkAMBP5lYVDDwpi wxuWXgEb/SZ73WAswhDYzg9ogfFPnHy7THTIiDtzn19HL1ZmCxcmWyF75B3lT+evX5ptwA9+m/xhk AsbjAeFoMNKzpmZ9DtWqKYWi1hGZ/DH6LVAgmc/9wozX8LMQPwOY8drflrtDLXOIMSK5sGoVV76UA r4jWOrA70ipIKWqQhfCqxWK2gAMtVCJbMJApMW/cdXfD5VO4Gx/9EBO4sq+6kmo/tVXMwsuyAcFml 1l+nPzc3EPZuJP7xTJHg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii42J-0006it-Jc; Thu, 19 Dec 2019 22:12:47 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41H-00052j-TQ for openwrt-devel@lists.openwrt.org; Thu, 19 Dec 2019 22:11:46 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id 9DA4A4BBE; Thu, 19 Dec 2019 23:11:42 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 1454c9b1; Thu, 19 Dec 2019 23:11:33 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Thu, 19 Dec 2019 23:11:13 +0100 Message-Id: <20191219221125.22646-5-ynezz@true.cz> In-Reply-To: <20191219221125.22646-1-ynezz@true.cz> References: <20191219221125.22646-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191219_141144_249731_B980A827 X-CRM114-Status: GOOD ( 14.46 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH ubus 04/16] iron out all extra compiler warnings X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org 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 19ccbb5093ce..421f244ad9dc 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 e0cde0bf3a86..004eaf3a7ae1 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 0274520f7d57..aab6629d1367 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 cdd1e6e1ed6a..120fb605e90a 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 74446f3fef51..97785a1e24cd 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 4da3c80e07f5..6fbbc0686af3 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 d6a72e73370b..c020ff416a32 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 6257f811a651..f19df9a875c7 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 712e7049946a..d36bcb73ddda 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 08314732567e..0c9cb9ae8208 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)