From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from buffalo.tulip.relay.mailchannels.net (buffalo.tulip.relay.mailchannels.net [23.83.218.24]) by sourceware.org (Postfix) with ESMTPS id C6DFC3858D1E for ; Tue, 18 Apr 2023 12:36:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C6DFC3858D1E 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 17C53141AFC; Tue, 18 Apr 2023 12:36:14 +0000 (UTC) Received: from pdx1-sub0-mail-a307.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 98310141691; Tue, 18 Apr 2023 12:36:13 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1681821373; a=rsa-sha256; cv=none; b=ckRPja+jtgW2IPRW51NPO66VGwBgKaz+purykOo6ycDB3halVcCG3le5A/8coSu2HWZq4D jXaMn0PGfFs6W5KYFaLZZ6dwRI1B0I7r2z6zxvPLP4chVnb/UDYKTp+9/FGhkNtc8lsQwq bcYvvN+JHWw5rOa744Wk62NiFBAPhav3FNO06wkEnUg3f2OLgHi+oQcqvDUCtTfP2C0Hjk LaiVrEhZakdQ1/NsVmZGxKI//OKke1pU7+gGVMKEm32tsmZUl5tlrTl5JGhax4HfmTAt9H d9ZGcYCLuy+vmqDidqix094G00F/yofDJ3CqmqnGcrBHp/Dg2f9H3getP2mMHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1681821373; 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=V0UsXD54VZ2VSkpNArjNLv5pdTRj54wLqhi6fpTQDVo=; b=cFpyqBWUYmleTiWnS6CCMotA+y8+tB67m5qxOmX+Yvlo2gBM/gj9rQ1lmN/3WzMrKKJnPQ lfE0DhcNYOAhQGuv17PAZhgAgESf0zmOmMNKz18bY6XhXpfsftO3qr/y07Rofx6f1mzMId 55jXfXGtFZzCLRVmmpK6ViSaDO/pN75rjhP7MN7xUyh6qj3h2sJKg6J45WogvGAQF6Dd37 lbNMLImYDZXiYY8kajDQ9QJleMFrTb7iEVh6Hor+auoLN0jZ/pUfBhh+1sNc1V6VIMoQWT Ai3YTjOukdV6RwsP2sjJODjNhGJ38QWoeXQHgEmwKyp1pd9ldPV0m8i4DoRSSA== ARC-Authentication-Results: i=1; rspamd-7f66b7b68c-nhr89; 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-Shelf: 7924e44d034638ff_1681821373874_340928844 X-MC-Loop-Signature: 1681821373874:2540648224 X-MC-Ingress-Time: 1681821373874 Received: from pdx1-sub0-mail-a307.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.103.24.113 (trex/6.7.2); Tue, 18 Apr 2023 12:36:13 +0000 Received: from [192.168.2.12] (bras-vprn-toroon4834w-lp130-09-174-91-45-80.dsl.bell.ca [174.91.45.80]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a307.dreamhost.com (Postfix) with ESMTPSA id 4Q13Lj1DL9zNm; Tue, 18 Apr 2023 05:36:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1681821373; bh=V0UsXD54VZ2VSkpNArjNLv5pdTRj54wLqhi6fpTQDVo=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=QaTLNnS3U1HWejVBGc8+/6o0jAbtfmXBKU1E3rKsaQQRdCNO32oB4PsfD/12X+BC3 OoZktwE1W09MoBtuIWMsooQ0AexNaIulmmBvbWid0trE6x+QYxmb2UUXTOkR6HEaVu Ioy69IlTQPYh5Z+5K/1v9Xb/hx4ROBRWp51qzRAvJvc4qGegqOwvG2ONGabXztezDt 4Vlxqo0XJaOovLEpQQnuBsRoEorESou9qbdNRakBTz+52fJG/EohycJClnxhJqztYk I5YVqKz6Cp2kzv+AB8GAcIves5oHkuNoSdIPsnnytFWdqfV1R0bjDMgGXfInZKmJr/ 4gqyP7LuRJvAg== Message-ID: <75834dd1-07b4-bbb2-32cc-ee4b55b7312a@gotplt.org> Date: Tue, 18 Apr 2023 08:36:12 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH 2/8] catgets/gencat.c: fix warn unused result Content-Language: en-US To: =?UTF-8?B?RnLDqWTDqXJpYyBCw6lyYXQ=?= , libc-alpha@sourceware.org References: <20230418121130.844302-1-fberat@redhat.com> <20230418121130.844302-3-fberat@redhat.com> From: Siddhesh Poyarekar In-Reply-To: <20230418121130.844302-3-fberat@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3038.5 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,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-04-18 08:11, Frédéric Bérat via Libc-alpha wrote: > Fix unused result warnings, detected when _FORTIFY_SOURCE is enabled in > glibc. > --- > catgets/gencat.c | 34 +++++++++++++++++++++++----------- > 1 file changed, 23 insertions(+), 11 deletions(-) > > diff --git a/catgets/gencat.c b/catgets/gencat.c > index 61ac797349..ecfdaa6e6d 100644 > --- a/catgets/gencat.c > +++ b/catgets/gencat.c > @@ -852,6 +852,7 @@ write_out (struct catalog *catalog, const char *output_name, > const char *strings; > size_t strings_size; > uint32_t *array1, *array2; > + uint32_t array_size; > size_t cnt; > int fd; > > @@ -927,12 +928,11 @@ write_out (struct catalog *catalog, const char *output_name, > obj.plane_size = best_size; > obj.plane_depth = best_depth; > > + array_size = best_size * best_depth * sizeof (uint32_t) * 3; We use c99 by default, so use declare and define here, no need for declarations at the top. > /* 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); That's a good cleanup. > obstack_init (&string_pool); > > set_run = catalog->all_sets; > @@ -985,22 +985,34 @@ write_out (struct catalog *catalog, const char *output_name, > } > > /* Write out header. */ > - write (fd, &obj, sizeof (obj)); > + if (write (fd, &obj, sizeof (obj)) < sizeof (obj)) > + error (EXIT_FAILURE, errno, > + gettext ("cannot write enough bytes to `%s'"), output_name); I wonder if this should use xwrite-like functionality, i.e. write iteratively until there's an error. > > /* 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); > + if (write (fd, array1, array_size) < array_size) > + error (EXIT_FAILURE, errno, > + gettext ("cannot write enough bytes to `%s'"), output_name); > + if (write (fd, array2, array_size) < array_size) > + error (EXIT_FAILURE, errno, > + gettext ("cannot write enough bytes to `%s'"), output_name); > #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); > + if (write (fd, array2, array_size) < array_size) > + error (EXIT_FAILURE, errno, > + gettext ("cannot write enough bytes to `%s'"), output_name); > + if (write (fd, array1, array_size) < array_size) > + error (EXIT_FAILURE, errno, > + gettext ("cannot write enough bytes to `%s'"), output_name); > #else > # error Cannot handle __BYTE_ORDER byte order > #endif > > /* Finally write the strings. */ > - write (fd, strings, strings_size); > + if (write (fd, strings, strings_size) < strings_size) > + error (EXIT_FAILURE, errno, > + gettext ("cannot write enough bytes to `%s'"), output_name); > > if (fd != STDOUT_FILENO) > close (fd); Likewise for all of these calls. It probably makes sense to implement a static int write_all() in this file that is similar to support/xwrite.c and then use it in place of all of these write calls. If this pattern is more common across glibc, perhaps putting it into include/unistd.h may make sense too. Thanks, Sid