From patchwork Sat Oct 3 17:21:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hauke Mehrtens X-Patchwork-Id: 1376320 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=2fP+V4ep; 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=aYtXCbCh; 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 4C3YcV6R5Cz9sTK 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=GZxgeXMuxjPm+C2zrQwPQotiv+WU0uZxmJYa9A4LDEI=; b=2fP+V4ep8Fv7dDamB44Ou6Qqk FR8NY1Lph3UnXRovQkjMzJ8fpmsBmbEsvKRbVixPHuP81QnpC3PWrmWCSkTkCxziT+WUsK8uqbUC7 FTcUh7S3LXF0zevSFKB+Cq3M8sVNJVNfmv3I1/fPdunemaO++WwTNPVzlaYj8UnSJtSrdxK78awx7 HEeLR7Kn/k6MppaaBXIqnVz4Jq7J46uNnJ+Jh3d/PTnyhVIyMUah2CFWvRvBn6Z/AvvrryuSv6+pt twuo/DGcXwow2yZlw3PBMHO85LCGKpgoqm8eWf5mkiUnIXDiJiiLfl3OqS2gRyzrf4+gCDRJCHnTu +rSdQW6MA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kOlEu-0008LB-9V; Sat, 03 Oct 2020 17:22:32 +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 1kOlEo-0008In-Cw 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 4C3YZm5qK9zQkSN; 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=1601745742; 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=aYtXCbChPXIo/cxZemK3/cPjEb8jjLEWpOGCBJ0mX2cPUEjzB4qTnQfgf6ly3CvJaMmIDO rGoAejvZba0wm8cbFPXJUy0tkMUGGxU/NDzS2qWl0X3R/zdpxRUnpUInjcaWNDW3r2Fnsl Y6Ab0ryU2JpDlk0bmmKYnkY6IaOEYcgvV6FlIRBGKGMCeRo3i4PSNI0GzhHw+qV1QINfXj 2X8xnwwmah9jv/JZuNGtialHO/a77qPc8xcmO+S5UxZciNaZaoJgTLfSUwULILnM4eDQ/m 4/VjyXfW6o/7DAaRHQ3wIbVas4ZqE/b00XF880OGq/SD1A3+vOY6zhDCEzgaUw== Received: from smtp2.mailbox.org ([80.241.60.241]) by gerste.heinlein-support.de (gerste.heinlein-support.de [91.198.250.173]) (amavisd-new, port 10030) with ESMTP id 6ivvON_GJ0j5; Sat, 3 Oct 2020 19:22:21 +0200 (CEST) From: Hauke Mehrtens To: openwrt-devel@lists.openwrt.org Subject: [PATCH uci 4/4] Replace malloc() + memset() with calloc() Date: Sat, 3 Oct 2020 19:21:58 +0200 Message-Id: <20201003172158.22552-5-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.05 / 15.00 / 15.00 X-Rspamd-Queue-Id: E133716A5 X-Rspamd-UID: 99acd0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201003_132226_583237_E1740AAB X-CRM114-Status: GOOD ( 12.46 ) 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_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 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 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; }