From patchwork Sun Oct 4 15:14:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hauke Mehrtens X-Patchwork-Id: 1376436 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=b16CjzIk; 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=DeADcwQQ; 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 4C46lS3LCsz9s1t for ; Mon, 5 Oct 2020 02:16:52 +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=GZxgeXMuxjPm+C2zrQwPQotiv+WU0uZxmJYa9A4LDEI=; b=b16CjzIkCk0JGky6DPcMnxdIP z2U3SlUOLkbx18R/bOTI/o12orGvpSO74jHJklVVrksfP1b4elyuslsXAkqoMP7gzq8WtUDnkNRQT nzdOOGK2JMwSFjIEeyZUKrvB2Mq430nxMmmjNe2OlcqV8LGq/HRFjyEDPgHc67jMV0846bz/QvtCf Z4d/2yZXaQHykTA634SU6kQYRenQyJWiYzJFn5SjfHtRxYXuUj4nl35r3UOqC4Cq4+cE8w80EIjqa of4MKol9ACSqX/CYkVepomveK+tAGW3fr29c6rUYQP2p6YLvj0GTRMKlLM8nHobrWmY4GTZ4UjQL2 EWMth8NLQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kP5jb-0006MU-54; Sun, 04 Oct 2020 15:15:35 +0000 Received: from mout-p-102.mailbox.org ([2001:67c:2050::465:102]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kP5jW-0006KL-TM for openwrt-devel@lists.openwrt.org; Sun, 04 Oct 2020 15:15:32 +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-102.mailbox.org (Postfix) with ESMTPS id 4C46jr2330zQlWf; Sun, 4 Oct 2020 17:15:28 +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=1601824526; 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=Ju0jGLm9RUdzDPvP8SL4OZhVqsYDOTVBsws2yUxo4EY=; b=DeADcwQQ9WYeLvjU9gBuLgQe6vIHJAHfOPS0XAxtdERA/gwqkUoOzcj0RQqcPlH0n2yyAf efTVQKXsvi96OnyIRz4xpjVNjPBTeMxXxEuFdDxG26ajk/XIrOUw8ORs8rbCqEPoLzwCug IQ7wxC1hVz+hcTmx4qLF5c/i0Vtyb9K21OT7kDcC3uaOdEMGnAEaLRmihcjPaCuVP7T43u XdmMzIVo0WfbXN6RpigDR82ItxTchti9ocWrLWXZiNJvzZ2QmRiH/Ke5/ZcQYjgeLsIJR7 mSg/joGEIbE0whltibzpdvaprsRxFGrP28rBeCfUUGMeTO0ENo+D8hoRM3dPDQ== 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 ASXsRn7nbMvx; Sun, 4 Oct 2020 17:15:25 +0200 (CEST) From: Hauke Mehrtens To: openwrt-devel@lists.openwrt.org Subject: [PATCH uci v2 4/4] Replace malloc() + memset() with calloc() Date: Sun, 4 Oct 2020 17:14:51 +0200 Message-Id: <20201004151451.16015-5-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.79 / 15.00 / 15.00 X-Rspamd-Queue-Id: 66C2917DA X-Rspamd-UID: 3634af X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201004_111531_052472_531AC6B2 X-CRM114-Status: GOOD ( 14.67 ) 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:102 listed in] [list.dnswl.org] -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 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 Instead of manually clearing the memory with memset() use calloc(). Signed-off-by: Hauke Mehrtens --- cli.c | 3 +-- libuci.c | 3 +-- ucimap.c | 6 ++---- util.c | 3 +-- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/cli.c b/cli.c index 6ba97ea..267437d 100644 --- a/cli.c +++ b/cli.c @@ -100,10 +100,9 @@ uci_lookup_section_ref(struct uci_section *s) ti = ti->next; } if (!ti) { - ti = malloc(sizeof(struct uci_type_list)); + ti = calloc(1, sizeof(struct uci_type_list)); if (!ti) return NULL; - memset(ti, 0, sizeof(struct uci_type_list)); ti->next = type_list; type_list = ti; ti->name = s->type; diff --git a/libuci.c b/libuci.c index 786d035..ae4c964 100644 --- a/libuci.c +++ b/libuci.c @@ -48,11 +48,10 @@ struct uci_context *uci_alloc_context(void) { struct uci_context *ctx; - ctx = (struct uci_context *) malloc(sizeof(struct uci_context)); + ctx = (struct uci_context *) calloc(1, sizeof(struct uci_context)); if (!ctx) return NULL; - memset(ctx, 0, sizeof(struct uci_context)); uci_list_init(&ctx->root); uci_list_init(&ctx->delta_path); uci_list_init(&ctx->backends); diff --git a/ucimap.c b/ucimap.c index c46cf45..758a5ea 100644 --- a/ucimap.c +++ b/ucimap.c @@ -661,11 +661,10 @@ ucimap_parse_section(struct uci_map *map, struct uci_sectionmap *sm, struct ucim size = sizeof(struct ucimap_list) + n_elements * sizeof(union ucimap_data); - data->list = malloc(size); + data->list = calloc(1, size); if (!data->list) goto error_mem; - memset(data->list, 0, size); data->list->size = n_elements; } else { ucimap_count_alloc(om, &n_alloc, &n_alloc_custom); @@ -897,10 +896,9 @@ ucimap_parse(struct uci_map *map, struct uci_package *pkg) continue; memset(sd, 0, sizeof(struct ucimap_section_data)); } else { - sd = malloc(sm->alloc_len); + sd = calloc(1, sm->alloc_len); if (!sd) continue; - memset(sd, 0, sm->alloc_len); sd = ucimap_ptr_section(sm, sd); } diff --git a/util.c b/util.c index 8572e81..61e42cd 100644 --- a/util.c +++ b/util.c @@ -36,10 +36,9 @@ __private void *uci_malloc(struct uci_context *ctx, size_t size) { void *ptr; - ptr = malloc(size); + ptr = calloc(1, size); if (!ptr) UCI_THROW(ctx, UCI_ERR_MEM); - memset(ptr, 0, size); return ptr; }