From patchwork Sat Oct 3 17:21:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hauke Mehrtens X-Patchwork-Id: 1376322 X-Patchwork-Delegate: hauke@hauke-m.de 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=2001:8b0:10b:1231::1; helo=merlin.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=hauke-m.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=fSXvX0Hw; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=hauke-m.de header.i=@hauke-m.de header.a=rsa-sha256 header.s=MBO0001 header.b=it0gdKWV; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (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 4C3YcV5sL5z9sSG for ; Sun, 4 Oct 2020 04:23:54 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=odG8MerOJ4vHuIkmWd0wQfnG6WSj14DYhWlGofTbxec=; b=fSXvX0Hw7+q0mftBYEZBYFNTa KY/PsnZeYVYL0rFUblOTcEUP9DerDeoWSvbgvjR3nUEG5Om2nvmhdWONpqVlRTb2XFqvH91JjqUu0 mQrESkJDyVaS74lA9FdqaMq0SWmOMiGCOlL14aRIieQpNcb0PGWhjmrvWCgRBChqAtJUZE6fBGufM +Ob4WCFz/TDMdfskx2zxAF2xmvkIjqLWy26CghgO0qRsIglN4ztrjqTnN1TLFZkC5Gb3Dgc155vOM vJp3UejxPTXymlng69iFBYq47A1TBboh4+g6N3O9qaFdcEH9l5LKIYOwPuQmIT0SVHbuIDlJTqMQ1 MewjYfu0w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kOlEs-0008Kn-Nn; Sat, 03 Oct 2020 17:22:30 +0000 Received: from mout-p-201.mailbox.org ([2001:67c:2050::465:201]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kOlEo-0008Ip-Cm for openwrt-devel@lists.openwrt.org; Sat, 03 Oct 2020 17:22:28 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4C3YZm6R2nzQl1t; Sat, 3 Oct 2020 19:22:24 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hauke-m.de; s=MBO0001; t=1601745743; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7X/wqvGuhtQND/ptInpuRfszYSeJZXPklfwR7m35Ll8=; b=it0gdKWVZbpTPNGK53BwSTMQRrI0Wy9dsDzUuMmGeyEZszc1O35AHXgbwBE+jwdKHFWOhH U+/aOzwrmu6xGIy2Bwl3G0XbaniBU1PIAJEOQKGn3sHjWIi1IYrPt3GMT+vvQmeZqmbONB 3vZuWVOiEkiwVsrjy86HEOKTQo4eLBiEyadRVE48J/b4+T9tdkFNC1Uqffv2nB3c9NqdOV wZt/hOUhPUCJiOT8fSaSK22I/1hmFNakhwDXAQ4fb8G5pTGOx8Q96nCorAyBVjInz55W4P 9XTHehJpEDpWKp82QF+ZjbMBlyrODyukkZ6QUfKkErW+63iH2dbK2IyhR2IYow== Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter06.heinlein-hosting.de (spamfilter06.heinlein-hosting.de [80.241.56.125]) (amavisd-new, port 10030) with ESMTP id RLKM4-y5dnmI; Sat, 3 Oct 2020 19:22:18 +0200 (CEST) From: Hauke Mehrtens To: openwrt-devel@lists.openwrt.org Subject: [PATCH uci 1/4] file: use size_t for position and pointer Date: Sat, 3 Oct 2020 19:21:55 +0200 Message-Id: <20201003172158.22552-2-hauke@hauke-m.de> In-Reply-To: <20201003172158.22552-1-hauke@hauke-m.de> References: <20201003172158.22552-1-hauke@hauke-m.de> MIME-Version: 1.0 X-MBO-SPAM-Probability: X-Rspamd-Score: -5.06 / 15.00 / 15.00 X-Rspamd-Queue-Id: 0258616FE X-Rspamd-UID: e5574e X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201003_132226_569213_93A9CE1F X-CRM114-Status: GOOD ( 15.27 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2001:67c:2050:0:0:0:465:201 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hauke Mehrtens , ynezz@true.cz Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org The bufsz variable is used to store the size of the buf memory region and pos is used to index a position in this memory. Use size_t for these variables in the internal handling instaed of int to not break with big files. Signed-off-by: Hauke Mehrtens --- file.c | 14 +++++++------- libuci.c | 2 +- uci_internal.h | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/file.c b/file.c index 5502a42..003f6c6 100644 --- a/file.c +++ b/file.c @@ -42,11 +42,11 @@ /* * Fetch a new line from the input stream and resize buffer if necessary */ -__private void uci_getln(struct uci_context *ctx, int offset) +__private void uci_getln(struct uci_context *ctx, size_t offset) { struct uci_parse_context *pctx = ctx->pctx; char *p; - int ofs; + size_t ofs; if (pctx->buf == NULL) { pctx->buf = uci_malloc(ctx, LINEBUF); @@ -116,7 +116,7 @@ static void skip_whitespace(struct uci_context *ctx) pctx->pos += 1; } -static inline void addc(struct uci_context *ctx, int *pos_dest, int *pos_src) +static inline void addc(struct uci_context *ctx, size_t *pos_dest, size_t *pos_src) { struct uci_parse_context *pctx = ctx->pctx; @@ -128,7 +128,7 @@ static inline void addc(struct uci_context *ctx, int *pos_dest, int *pos_src) /* * parse a double quoted string argument from the command line */ -static void parse_double_quote(struct uci_context *ctx, int *target) +static void parse_double_quote(struct uci_context *ctx, size_t *target) { struct uci_parse_context *pctx = ctx->pctx; char c; @@ -163,7 +163,7 @@ static void parse_double_quote(struct uci_context *ctx, int *target) /* * parse a single quoted string argument from the command line */ -static void parse_single_quote(struct uci_context *ctx, int *target) +static void parse_single_quote(struct uci_context *ctx, size_t *target) { struct uci_parse_context *pctx = ctx->pctx; char c; @@ -192,7 +192,7 @@ static void parse_single_quote(struct uci_context *ctx, int *target) /* * parse a string from the command line and detect the quoting style */ -static void parse_str(struct uci_context *ctx, int *target) +static void parse_str(struct uci_context *ctx, size_t *target) { struct uci_parse_context *pctx = ctx->pctx; bool next = true; @@ -241,7 +241,7 @@ done: static int next_arg(struct uci_context *ctx, bool required, bool name, bool package) { struct uci_parse_context *pctx = ctx->pctx; - int val, ptr; + size_t val, ptr; skip_whitespace(ctx); val = ptr = pctx_pos(pctx); diff --git a/libuci.c b/libuci.c index 140edf2..786d035 100644 --- a/libuci.c +++ b/libuci.c @@ -148,7 +148,7 @@ uci_get_errorstr(struct uci_context *ctx, char **dest, const char *prefix) err = UCI_ERR_UNKNOWN; if (ctx && ctx->pctx && (err == UCI_ERR_PARSE)) { - snprintf(error_info, sizeof(error_info) - 1, " (%s) at line %d, byte %d", + snprintf(error_info, sizeof(error_info) - 1, " (%s) at line %d, byte %zu", (ctx->pctx->reason ? ctx->pctx->reason : "unknown"), ctx->pctx->line, ctx->pctx->byte); } diff --git a/uci_internal.h b/uci_internal.h index f00b394..3a94dbb 100644 --- a/uci_internal.h +++ b/uci_internal.h @@ -23,7 +23,7 @@ struct uci_parse_context /* error context */ const char *reason; int line; - int byte; + size_t byte; /* private: */ struct uci_package *package; @@ -32,8 +32,8 @@ struct uci_parse_context FILE *file; const char *name; char *buf; - int bufsz; - int pos; + size_t bufsz; + size_t pos; }; #define pctx_pos(pctx) ((pctx)->pos) #define pctx_str(pctx, i) (&(pctx)->buf[(i)]) @@ -54,7 +54,7 @@ __private struct uci_package *uci_alloc_package(struct uci_context *ctx, const c __private FILE *uci_open_stream(struct uci_context *ctx, const char *filename, const char *origfilename, int pos, bool write, bool create); __private void uci_close_stream(FILE *stream); -__private void uci_getln(struct uci_context *ctx, int offset); +__private void uci_getln(struct uci_context *ctx, size_t offset); __private void uci_parse_error(struct uci_context *ctx, char *reason); __private void uci_alloc_parse_context(struct uci_context *ctx);