From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from aye.elm.relay.mailchannels.net (aye.elm.relay.mailchannels.net [23.83.212.6]) by sourceware.org (Postfix) with ESMTPS id 3C2F93857BB2 for ; Tue, 18 Apr 2023 12:47:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C2F93857BB2 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 CD6223E1F91; Tue, 18 Apr 2023 12:47:36 +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 453783E1F70; Tue, 18 Apr 2023 12:47:36 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1681822056; a=rsa-sha256; cv=none; b=FfzSNEztIDa19X1Ws6SPE0kHp70JpaP5wHY9B7MnjTgfXLpgVb1+UCEXnJU82iHd/jv1Y5 0jqCPmS+PJCTYk2soM7xdrAYcGk8Gwsk3nGWV9r2btBJzhs5kc2qSB9dL6yB/wEiog5xD0 WDtoayBJPxvgzI+Vy9LKOs5oQXn5y2ASAH6XeOJpOQz/dskq8uV7R1YW59nEDZwT0A8Ct1 NyLTT9PCvcfudUpF8BmnQhpWXPu95NolKCbVe5K9anp6MjKLP6gI2Q5urWPUxJjh2I+wXZ xMlRZpQ75BaY4gqoXuYhq9C6TkKcXGISr0fVbQs/lBydSNvjdF4JbuOMLveEzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1681822056; 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=H4uH0GcbCIQdu+wwqGzt90PzR4CFjB1L3Ae1az+EICY=; b=2ueFqWNKy9tKpbA1CSN/QY+gsX2+WTW39Fz1RZy4hU9+NREAiDMGTVXZDV4N/ShY9j6NEF IoQ29lrnfGvenCIv4VHBHA537pIJQC/pqGY309f3merarRX9LUmrCRuKjY1USQvSFNr5/O Kg5r7ash5PTksQ0QtNT+9Dqd0xxr4+W1JXhD0Hpc3jZBZi05p6tYg55v5LtqyhTNxSP2o3 IhdBa1hMLTyYOdQhaY0rYfsurPn4/rUx4ef1BWFzSsDjarD7eMTu7FIXeUb86CJVqe2BK3 GOzRTlQrKz13sox1VJPigvk48SVmCO6UZ3Jw6tgpl/+CCYjB48rDHtXbjGXX3w== ARC-Authentication-Results: i=1; rspamd-548d6c8f77-z7j7w; 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-Shrill-Troubled: 235979801f8516b9_1681822056559_1547036033 X-MC-Loop-Signature: 1681822056559:2351744418 X-MC-Ingress-Time: 1681822056558 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.125.42.190 (trex/6.7.2); Tue, 18 Apr 2023 12:47:36 +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 4Q13bq5wclzLs; Tue, 18 Apr 2023 05:47:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1681822056; bh=H4uH0GcbCIQdu+wwqGzt90PzR4CFjB1L3Ae1az+EICY=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=BAqeLCAPad6j6kjXGvLb/DXWxkKpMxIbcTxSEc+ZDu8mWtCYe3oJMAmuNQuAOM+Yq lZa4IetbICdomWq9sdO1xyvbcFEYFMMGsfiryEOiTKKJA/zRo+0yG58eeUsaXSqcCZ Xjm/fdqk5/pWWPjnOUXmVIGSZjeEKxkEeb9oSTD1VW69CmWDxc1ccsUDXaBFmQBeWm ap7+elpEk4aqqVMK0ODzgYIllaH8DFir4q0JESw5osM+J2+/ccRjvIb36YyIjjb3YA PmO2MbC9H+wiQVtnz8t4R6etGaJhJDO2DpkIEKJPriZdFmQH4amxSlMQgntHd06YHn GaFup//WsWQtg== Message-ID: <36654603-2cf0-3891-4bbb-41d35a06c4ed@gotplt.org> Date: Tue, 18 Apr 2023 08:47:34 -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 5/8] malloc/{memusage.c, memusagestat.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-6-fberat@redhat.com> From: Siddhesh Poyarekar In-Reply-To: <20230418121130.844302-6-fberat@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3038.8 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_H2,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. > --- > malloc/memusage.c | 38 ++++++++++++++++++++++++++------------ > malloc/memusagestat.c | 13 +++++++++---- > 2 files changed, 35 insertions(+), 16 deletions(-) > > diff --git a/malloc/memusage.c b/malloc/memusage.c > index 2a3a508557..6251e039b0 100644 > --- a/malloc/memusage.c > +++ b/malloc/memusage.c > @@ -18,6 +18,8 @@ > > #include > #include > +#include > +#include > #include > #include > #include > @@ -210,10 +212,12 @@ update_data (struct header *result, size_t len, size_t old_len) > gettime (&buffer[idx]); > > /* Write out buffer if it is full. */ > - if (idx + 1 == buffer_size) > - write (fd, buffer, buffer_size * sizeof (struct entry)); > - else if (idx + 1 == 2 * buffer_size) > - write (fd, &buffer[buffer_size], buffer_size * sizeof (struct entry)); > + if (idx + 1 == buffer_size || idx + 1 == 2 * buffer_size) > + { > + uint32_t write_size = buffer_size * sizeof (buffer[0]); > + if (write (fd, &buffer[idx + 1 - buffer_size], write_size) < write_size) > + error(EXIT_FAILURE, errno, "cannot write buffer"); Same as patch 2/8, maybe it makes sense to make a higher level abstraction for read and write to ensure all contents are read/written. Thanks, Sid > + } > } > } > > @@ -299,8 +303,10 @@ me (void) > first.stack = 0; > gettime (&first); > /* Write it two times since we need the starting and end time. */ > - write (fd, &first, sizeof (first)); > - write (fd, &first, sizeof (first)); > + if (write (fd, &first, sizeof (first)) < sizeof (first)) > + error(EXIT_FAILURE, errno, "cannot write entry"); > + if (write (fd, &first, sizeof (first)) < sizeof (first)) > + error(EXIT_FAILURE, errno, "cannot write entry"); > > /* Determine the buffer size. We use the default if the > environment variable is not present. */ > @@ -850,24 +856,32 @@ dest (void) > if (fd != -1) > { > /* Write the partially filled buffer. */ > + struct entry *start = buffer; > + uint32_t write_cnt = buffer_cnt; > + > if (buffer_cnt > buffer_size) > - write (fd, buffer + buffer_size, > - (buffer_cnt - buffer_size) * sizeof (struct entry)); > - else > - write (fd, buffer, buffer_cnt * sizeof (struct entry)); > + { > + start = buffer + buffer_size; > + write_cnt = buffer_cnt - buffer_size; > + } > + > + if (write(fd, start, write_cnt * sizeof (buffer[0])) < sizeof (buffer[0])) > + error(EXIT_FAILURE, errno, "cannot write buffer"); > > /* Go back to the beginning of the file. We allocated two records > here when we opened the file. */ > lseek (fd, 0, SEEK_SET); > /* Write out a record containing the total size. */ > first.stack = peak_total; > - write (fd, &first, sizeof (struct entry)); > + if (write (fd, &first, sizeof (first)) < sizeof (first)) > + error(EXIT_FAILURE, errno, "cannot write first"); > /* Write out another record containing the maximum for heap and > stack. */ > first.heap = peak_heap; > first.stack = peak_stack; > gettime (&first); > - write (fd, &first, sizeof (struct entry)); > + if (write (fd, &first, sizeof (first)) < sizeof (first)) > + error(EXIT_FAILURE, errno, "cannot write first"); > > /* Close the file. */ > close (fd); > diff --git a/malloc/memusagestat.c b/malloc/memusagestat.c > index 67c5131f79..3853f00b9b 100644 > --- a/malloc/memusagestat.c > +++ b/malloc/memusagestat.c > @@ -188,7 +188,8 @@ main (int argc, char *argv[]) > total = st.st_size / sizeof (struct entry) - 2; > > /* Read the administrative information. */ > - read (fd, headent, sizeof (headent)); > + if (read (fd, headent, sizeof (headent)) < sizeof (headent)) > + error(EXIT_FAILURE, errno, "cannot read entry header"); > maxsize_heap = headent[1].heap; > maxsize_stack = headent[1].stack; > maxsize_total = headent[0].stack; > @@ -220,7 +221,9 @@ main (int argc, char *argv[]) > > /* Write the computed values in the file. */ > lseek (fd, 0, SEEK_SET); > - write (fd, headent, 2 * sizeof (struct entry)); > + if (write (fd, headent, sizeof (headent)) < sizeof (headent)) > + error(EXIT_FAILURE, errno, "cannot write entries"); > + > } > > if (also_total) > @@ -372,7 +375,8 @@ main (int argc, char *argv[]) > size_t new[2]; > uint64_t now; > > - read (fd, &entry, sizeof (entry)); > + if (read (fd, &entry, sizeof (entry)) < sizeof (entry)) > + error(EXIT_FAILURE, errno, "cannot read entry"); > > now = ((uint64_t) entry.time_high) << 32 | entry.time_low; > > @@ -455,7 +459,8 @@ main (int argc, char *argv[]) > size_t xpos; > uint64_t now; > > - read (fd, &entry, sizeof (entry)); > + if (read (fd, &entry, sizeof (entry)) < sizeof (entry)) > + error(EXIT_FAILURE, errno, "cannot read entry"); > > now = ((uint64_t) entry.time_high) << 32 | entry.time_low; > xpos = 40 + ((xsize - 80) * (now - start_time)) / total_time;