From patchwork Sun Oct 4 15:14:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hauke Mehrtens X-Patchwork-Id: 1376438 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=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=GE8o4Cn7; 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=DsND6eLy; 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 4C46lV1PxYz9s1t for ; Mon, 5 Oct 2020 02:16:53 +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=GE8o4Cn7IdAhBiEfAIssHJxsz NqW5X3lrI2/pUGN0BUcX0XSKTJ6r8In19OJM38qONu8q/KuJtohoOP0Bw4hBI8xWxU6S9V5OGtppT B/ZWavKDcTy+TWTnhR3mzfCjBy4RCU3F1Qxghkrvq0bRxG8yUlzc5+rCoK0u3bt/5LSGpMj+yYhLw OuUaPTwxwqpF/XO2GQsF3QbCLBoKA2GcElV9OnjGmq6AY9N6qBYdS/emPsk435McXVC1SWRXEuclI ktF6KAWsd10n2m0XVOxcAWYdE3RHBhL85WNyAEbLZs7U5abXKC3woj4E9iEmvXWeNwE9XAJEXmKj9 ba3xC+PAg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kP5jh-0006OE-IR; Sun, 04 Oct 2020 15:15:41 +0000 Received: from mout-p-201.mailbox.org ([80.241.56.171]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kP5jX-0006KG-Aw for openwrt-devel@lists.openwrt.org; Sun, 04 Oct 2020 15:15:33 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (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 4C46jq2ST3zQlLp; Sun, 4 Oct 2020 17:15:27 +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=1601824525; 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=DsND6eLyzOIfBO4F6db4tzi6xH+Woi5QzUlOiYRCkg7sc6Ts5QW1gTs9F/iCNrtQdTkXEE UbCU7IHsJaRVGizxUvDf4kBtiEcC0OHUbXbAuy/F7rOlYwjfBxxSA9dnRVlFtXNlEuFocq fptYZAzM9U764NFJ0ZaGg2K65oLpcFvmdDYWTfc38AF+V1iXmcNS8Bisne8kKgb2nNFMPw AL0ovIZqpujZsQi6nm/rD8GY7KOJL883IuJnqJRasRp7ZjJl/0MpE0shZnc67OpycVieK/ +b2uqNHz5VaL4zSkpzimEYAguICY/mreIwCNb6oJK26Wly3DejYzH+rj3DX3og== Received: from smtp1.mailbox.org ([80.241.60.240]) by gerste.heinlein-support.de (gerste.heinlein-support.de [91.198.250.173]) (amavisd-new, port 10030) with ESMTP id FHRuZhHHA3sa; Sun, 4 Oct 2020 17:15:23 +0200 (CEST) From: Hauke Mehrtens To: openwrt-devel@lists.openwrt.org Subject: [PATCH uci v2 1/4] file: use size_t for position and pointer Date: Sun, 4 Oct 2020 17:14:48 +0200 Message-Id: <20201004151451.16015-2-hauke@hauke-m.de> In-Reply-To: <20201004151451.16015-1-hauke@hauke-m.de> References: <20201004151451.16015-1-hauke@hauke-m.de> MIME-Version: 1.0 X-MBO-SPAM-Probability: X-Rspamd-Score: -4.40 / 15.00 / 15.00 X-Rspamd-Queue-Id: 65BEE17DD X-Rspamd-UID: 366b6a X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201004_111531_509716_776F222F X-CRM114-Status: GOOD ( 17.30 ) X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [80.241.56.171 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [80.241.56.171 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders 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);