aboutsummaryrefslogtreecommitdiff
path: root/malloc/memusagestat.c
diff options
context:
space:
mode:
authorFrédéric Bérat <fberat@redhat.com>2023-06-01 16:27:43 +0200
committerSiddhesh Poyarekar <siddhesh@sourceware.org>2023-06-01 13:00:03 -0400
commitb97c5efdcae89d17c8ea715a5b814aab9d3cf618 (patch)
tree06968ed0830bfef46900ee809cedac886f4994f6 /malloc/memusagestat.c
parente76ff03108f427e8629d24599c6c1bad8b8b35dd (diff)
downloadglibc-b97c5efdcae89d17c8ea715a5b814aab9d3cf618.tar.xz
glibc-b97c5efdcae89d17c8ea715a5b814aab9d3cf618.zip
malloc/{memusage.c, memusagestat.c}: fix warn unused result
Fix unused result warnings, detected when _FORTIFY_SOURCE is enabled in glibc. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Diffstat (limited to 'malloc/memusagestat.c')
-rw-r--r--malloc/memusagestat.c48
1 files changed, 44 insertions, 4 deletions
diff --git a/malloc/memusagestat.c b/malloc/memusagestat.c
index 67c5131f79..cc066d4af9 100644
--- a/malloc/memusagestat.c
+++ b/malloc/memusagestat.c
@@ -114,6 +114,45 @@ static int time_based;
static int also_total = 0;
+static void
+read_all (int fd, void *buffer, size_t length)
+{
+ char *p = buffer;
+ char *end = p + length;
+ while (p < end)
+ {
+ ssize_t ret = read (fd, p, end - p);
+ if (ret < 0)
+ error (EXIT_FAILURE, errno,
+ gettext ("read of %zu bytes failed after %td: %m"),
+ length, p - (char *) buffer);
+
+ p += ret;
+ }
+}
+
+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;
+ }
+}
+
+
int
main (int argc, char *argv[])
{
@@ -188,7 +227,7 @@ main (int argc, char *argv[])
total = st.st_size / sizeof (struct entry) - 2;
/* Read the administrative information. */
- read (fd, headent, sizeof (headent));
+ read_all (fd, headent, sizeof (headent));
maxsize_heap = headent[1].heap;
maxsize_stack = headent[1].stack;
maxsize_total = headent[0].stack;
@@ -220,7 +259,8 @@ main (int argc, char *argv[])
/* Write the computed values in the file. */
lseek (fd, 0, SEEK_SET);
- write (fd, headent, 2 * sizeof (struct entry));
+ write_all (fd, headent, sizeof (headent));
+
}
if (also_total)
@@ -372,7 +412,7 @@ main (int argc, char *argv[])
size_t new[2];
uint64_t now;
- read (fd, &entry, sizeof (entry));
+ read_all (fd, &entry, sizeof (entry));
now = ((uint64_t) entry.time_high) << 32 | entry.time_low;
@@ -455,7 +495,7 @@ main (int argc, char *argv[])
size_t xpos;
uint64_t now;
- read (fd, &entry, sizeof (entry));
+ read_all (fd, &entry, sizeof (entry));
now = ((uint64_t) entry.time_high) << 32 | entry.time_low;
xpos = 40 + ((xsize - 80) * (now - start_time)) / total_time;