[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] test-select: avoid warn_unused_result warnings
From: |
Jim Meyering |
Subject: |
[PATCH] test-select: avoid warn_unused_result warnings |
Date: |
Wed, 13 Oct 2010 10:19:33 +0200 |
Hi Paolo,
Is this change ok with you?
Without it, I see many warnings like this when running
coreutils's "make check" (with --enable-gcc-warnings):
test-select.c: In function 'test_pair':
test-select.c:330: warning: ignoring return value of 'write', declared \
with attribute warn_unused_result
test-select.c:336: warning: ignoring return value of 'read', declared \
with attribute warn_unused_result
>From 589ff057183416c257c98b4364e2ca03ea4feece Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Wed, 13 Oct 2010 10:15:38 +0200
Subject: [PATCH] test-select: avoid warn_unused_result warnings
* tests/test-select.c: Include "macros.h".
ASSERT that each call to read, write, and pipe succeeds.
While not technically required, also check each "close".
---
ChangeLog | 5 +++++
tests/test-select.c | 44 +++++++++++++++++++++++---------------------
2 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 03bdd3f..55e3eb0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2010-10-13 Jim Meyering <address@hidden>
+ test-select: avoid warn_unused_result warnings
+ * tests/test-select.c: Include "macros.h".
+ ASSERT that each call to read, write, and pipe succeeds.
+ While not technically required, also check each "close".
+
test-symlinkat: remove declaration of unused local
* tests/test-symlinkat.c (main): Remove unused local, "buf".
diff --git a/tests/test-select.c b/tests/test-select.c
index 884e823..9c895c3 100644
--- a/tests/test-select.c
+++ b/tests/test-select.c
@@ -48,6 +48,8 @@ SIGNATURE_CHECK (FD_ZERO, void, (fd_set *));
#include <sys/ioctl.h>
#include <errno.h>
+#include "macros.h"
+
enum { SEL_IN = 1, SEL_OUT = 2, SEL_EXC = 4 };
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
@@ -263,9 +265,9 @@ test_connect_first (void)
addrlen = sizeof (ia);
c2 = accept (s, (struct sockaddr *) &ia, &addrlen);
- close (s);
- close (c1);
- close (c2);
+ ASSERT (close (s) == 0);
+ ASSERT (close (c1) == 0);
+ ASSERT (close (c2) == 0);
}
@@ -289,26 +291,26 @@ test_accept_first (void)
{
addrlen = sizeof (ia);
c = accept (s, (struct sockaddr *) &ia, &addrlen);
- close (s);
- write (c, "foo", 3);
- read (c, buf, 3);
+ ASSERT (close (s) == 0);
+ ASSERT (write (c, "foo", 3) == 3);
+ ASSERT (read (c, buf, 3) == 3);
shutdown (c, SHUT_RD);
- close (c);
+ ASSERT (close (c) == 0);
exit (0);
}
else
{
- close (s);
+ ASSERT (close (s) == 0);
c = connect_to_socket (true);
if (do_select_nowait (c, SEL_OUT) != SEL_OUT)
failed ("cannot write after blocking connect");
- write (c, "foo", 3);
+ ASSERT (write (c, "foo", 3) == 3);
wait (&pid);
if (do_select_wait (c, SEL_IN) != SEL_IN)
failed ("cannot read data left in the socket by closed process");
- read (c, buf, 3);
- write (c, "foo", 3);
- close (c);
+ ASSERT (read (c, buf, 3) == 3);
+ ASSERT (write (c, "foo", 3) == 3);
+ ASSERT (close (c) == 0);
}
#endif
}
@@ -325,13 +327,13 @@ test_pair (int rd, int wd)
if (do_select_nowait (wd, SEL_IN | SEL_OUT | SEL_EXC) != SEL_OUT)
failed ("expecting writability before writing");
- write (wd, "foo", 3);
+ ASSERT (write (wd, "foo", 3) == 3);
if (do_select_wait (rd, SEL_IN) != SEL_IN)
failed ("expecting readability after writing");
if (do_select_nowait (rd, SEL_IN) != SEL_IN)
failed ("expecting readability after writing");
- read (rd, buf, 3);
+ ASSERT (read (rd, buf, 3) == 3);
}
@@ -347,12 +349,12 @@ test_socket_pair (void)
int c1 = connect_to_socket (false);
int c2 = accept (s, (struct sockaddr *) &ia, &addrlen);
- close (s);
+ ASSERT (close (s) == 0);
test_pair (c1, c2);
- close (c1);
- write (c2, "foo", 3);
- close (c2);
+ ASSERT (close (c1) == 0);
+ ASSERT (write (c2, "foo", 3) == 3);
+ ASSERT (close (c2) == 0);
}
@@ -363,10 +365,10 @@ test_pipe (void)
{
int fd[2];
- pipe (fd);
+ ASSERT (pipe (fd) == 0);
test_pair (fd[0], fd[1]);
- close (fd[0]);
- close (fd[1]);
+ ASSERT (close (fd[0]) == 0);
+ ASSERT (close (fd[1]) == 0);
}
--
1.7.3.1.104.gc752e
- [PATCH] test-select: avoid warn_unused_result warnings,
Jim Meyering <=