From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id A63393858C2D for ; Tue, 18 Apr 2023 12:11:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A63393858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681819909; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JxM/zCv3gyTQ9UppeXT7zaUQgDX2Tuvio7fe7wUydzc=; b=bM5VtDeqxW43aBBo9MvDJPt/eqEtDMOz4i424I5rIwZFbrMtzU3P5RQkhmS+o31c7BjPos 4aBV3vytDNelNs4sM9fGz8QC9WWUp9OWBAdE4pis/KKjezxI07GxOoiedcCKjsHtDo5br7 CQS58aIdYp4JRntJPU51YqLirHY8Sc8= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-656-gJNoVACkMNesB6YK7ZEwhw-1; Tue, 18 Apr 2023 08:11:40 -0400 X-MC-Unique: gJNoVACkMNesB6YK7ZEwhw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6B87329DD991 for ; Tue, 18 Apr 2023 12:11:40 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.127]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E2D1340C83A9; Tue, 18 Apr 2023 12:11:39 +0000 (UTC) From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20B=C3=A9rat?= To: libc-alpha@sourceware.org Cc: sipoyare@redhat.com Subject: [PATCH 5/8] malloc/{memusage.c,memusagestat.c}: fix warn unused result Date: Tue, 18 Apr 2023 14:11:27 +0200 Message-Id: <20230418121130.844302-6-fberat@redhat.com> In-Reply-To: <20230418121130.844302-1-fberat@redhat.com> References: <20230418121130.844302-1-fberat@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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: 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"); + } } } @@ -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; -- 2.39.2