From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from buffalo.birch.relay.mailchannels.net (buffalo.birch.relay.mailchannels.net [23.83.209.24]) by sourceware.org (Postfix) with ESMTPS id DCC87385840D for ; Thu, 1 Jun 2023 16:48:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DCC87385840D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 132C27E284D; Thu, 1 Jun 2023 16:48:00 +0000 (UTC) Received: from pdx1-sub0-mail-a202.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 88EC67E12C6; Thu, 1 Jun 2023 16:47:59 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1685638079; a=rsa-sha256; cv=none; b=pQd1Cg66woo304SAdILO8+OskgmUtlPNFw9olzWXAlJBsdmYyu+6CNlI7jJo0RwVe9bbGS +5ZB0imUTcXguAXC0ycSmPppAHod11PWLIiBoHGcQIXxw5YytP/zS3DDjeSoNP/sFAX8/K Zv0T5OL3RMIobWFA49sBHM8KtEkUTqlSWXUPxOUGwPAzqanjPYtePk7jlu0n44vU16/sK+ XLALZNOV2k3uuHu26TewLhLfjL2e5xvREkTSy9vxn/9DVPBtolOqjHlpxcuM3spsXaSNfj 9Nj7eAU1Po3BO81WO1/kZ23VwJT5POIADmFIFVxfEjZeCLqCEoTM3gTLzjpEow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1685638079; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=C4AfT6cAXzI9Csn4pbRY1eIz+YagK1QW7EiGJhS1ziQ=; b=LikA6E8cGOvyonMn+/X1njF+yUj191N+v0SwlqKkcYqfKrkLt0itTZUpX2tN8avlWQG18z JWYJkaUYJ24TjdyqtKeOpkZ6596vza/eL1d2DUp86FafPzRYw7B/L1/Kfjjh1zt/OUoR2C P8giRZPwNN8CXGE6gIGC6oS9axr1pQYLF74ohicPR7CI2m8ivmtOBNoKQPo4Wotm86ZkzQ +fG4VI/VLvaeb873C9ziegxWGq+Xdgam4mrOxu/Gp+aj7JusSys5AvPBB3TfgOrnvdg1/t lz9NdYDAgS1zC4Py1wdsU4/Go/QVuQA2SMOwdVZpQE/XAzbxac4PiBpwkV6bVA== ARC-Authentication-Results: i=1; rspamd-58dcc7d645-whjrv; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Plucky-Coil: 2009765176a26270_1685638079844_4017325110 X-MC-Loop-Signature: 1685638079844:3929254405 X-MC-Ingress-Time: 1685638079844 Received: from pdx1-sub0-mail-a202.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.125.42.141 (trex/6.8.1); Thu, 01 Jun 2023 16:47:59 +0000 Received: from [192.168.0.182] (bras-vprn-toroon4834w-lp130-02-142-113-138-85.dsl.bell.ca [142.113.138.85]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a202.dreamhost.com (Postfix) with ESMTPSA id 4QXBrv0JN6zRq; Thu, 1 Jun 2023 09:47:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1685638079; bh=C4AfT6cAXzI9Csn4pbRY1eIz+YagK1QW7EiGJhS1ziQ=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=sGqZ+Lf0t3SKtrZZiI/UVUCAmIh7GF4cOcaEE1bSr4z2/eiaF/g32L1Xmi1gS6HOg X/FPWbSC9+wETKno/h3rUpMbhvjYfxJCcN1DLLN8M7tpor0KdX4joKtdQB2GnLYZyH CP0j7+QSembWREmPH4R5X6xPo+WQOiwHDEdvFy7hD477TCBWqEtgsrMBdU6AMJgXrt 1a3Crkef9FradMzfKfCnREa57l9zsvHGl2wX1CfGFS0ZpSauPLH1qdNHmkcXH3dLrE D2idpGJJHyp4+Nx6xGQ//SejdJUXXOJ+3vVoGBKI057/GrslsVPtqVqF2PQYh3VcX0 DTIHzQEFEgdTg== Message-ID: Date: Thu, 1 Jun 2023 12:47:57 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v5 01/12] catgets/gencat.c: fix warn unused result Content-Language: en-US To: =?UTF-8?B?RnLDqWTDqXJpYyBCw6lyYXQ=?= , libc-alpha@sourceware.org References: <20230601142747.104444-1-fberat@redhat.com> From: Siddhesh Poyarekar In-Reply-To: <20230601142747.104444-1-fberat@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3037.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2023-06-01 10:27, Frédéric Bérat wrote: > Fix unused result warnings, detected when _FORTIFY_SOURCE is enabled in > glibc. > --- > Changes since v4: > - Mark strings for translation with gettext. > - Fixed typo in (ret == 0) case > > catgets/gencat.c | 41 ++++++++++++++++++++++++++++++----------- > 1 file changed, 30 insertions(+), 11 deletions(-) LGTM. You're moving write_all into a separate file later, so OK. Reviewed-by: Siddhesh Poyarekar > > diff --git a/catgets/gencat.c b/catgets/gencat.c > index 61ac797349..826596c2e4 100644 > --- a/catgets/gencat.c > +++ b/catgets/gencat.c > @@ -838,6 +838,26 @@ invalid character: message ignored")); > return current; > } > > +static void > +write_all (int fd, const void *buffer, size_t length) > +{ > + const char *p = buffer; > + const char *end = p + length; > + while (p < end) > + { > + ssize_t ret = write (fd, p, end - p); > + if (ret < 0) > + error (EXIT_FAILURE, errno, > + gettext ("write of %zu bytes failed after %td: %m"), > + length, p - (const char *) buffer); > + > + if (ret == 0) > + error (EXIT_FAILURE, 0, > + gettext ("write returned 0 after writing %td bytes of %zu"), > + p - (const char *) buffer, length); > + p += ret; > + } > +} > > static void > write_out (struct catalog *catalog, const char *output_name, > @@ -927,12 +947,11 @@ write_out (struct catalog *catalog, const char *output_name, > obj.plane_size = best_size; > obj.plane_depth = best_depth; > > + uint32_t array_size = best_size * best_depth * sizeof (uint32_t) * 3; > /* Allocate room for all needed arrays. */ > - array1 = > - (uint32_t *) alloca (best_size * best_depth * sizeof (uint32_t) * 3); > - memset (array1, '\0', best_size * best_depth * sizeof (uint32_t) * 3); > - array2 > - = (uint32_t *) alloca (best_size * best_depth * sizeof (uint32_t) * 3); > + array1 = (uint32_t *) alloca (array_size); > + memset (array1, '\0', array_size); > + array2 = (uint32_t *) alloca (array_size); > obstack_init (&string_pool); > > set_run = catalog->all_sets; > @@ -985,22 +1004,22 @@ write_out (struct catalog *catalog, const char *output_name, > } > > /* Write out header. */ > - write (fd, &obj, sizeof (obj)); > + write_all(fd, &obj, sizeof (obj)); > > /* We always write out the little endian version of the index > arrays. */ > #if __BYTE_ORDER == __LITTLE_ENDIAN > - write (fd, array1, best_size * best_depth * sizeof (uint32_t) * 3); > - write (fd, array2, best_size * best_depth * sizeof (uint32_t) * 3); > + write_all(fd, array1, array_size); > + write_all(fd, array2, array_size); > #elif __BYTE_ORDER == __BIG_ENDIAN > - write (fd, array2, best_size * best_depth * sizeof (uint32_t) * 3); > - write (fd, array1, best_size * best_depth * sizeof (uint32_t) * 3); > + write_all(fd, array2, array_size); > + write_all(fd, array1, array_size); > #else > # error Cannot handle __BYTE_ORDER byte order > #endif > > /* Finally write the strings. */ > - write (fd, strings, strings_size); > + write_all(fd, strings, strings_size); > > if (fd != STDOUT_FILENO) > close (fd);