[PATCH] Check ftruncate return value

6 views
Skip to first unread message

er...@munsonfam.org

unread,
Aug 18, 2019, 9:55:53 PM8/18/19
to libhug...@googlegroups.com, Eric B Munson
From: Eric B Munson <er...@munsonfam.org>

If the system call failes, there isn't any reason to continue with the
test.

Signed-off-by: Eric B Munson <er...@munsonfam.org>
---
tests/icache-hygiene.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tests/icache-hygiene.c b/tests/icache-hygiene.c
index 0e344d9..caacab0 100644
--- a/tests/icache-hygiene.c
+++ b/tests/icache-hygiene.c
@@ -155,11 +155,13 @@ static void test_once(int fd)
{
void *p, *q;

- ftruncate(fd, 0);
+ if (ftruncate(fd, 0) < 0)
+ FAIL("ftruncate failed: %s", strerror(errno));

if (sigsetjmp(sig_escape, 1)) {
sig_expected = NULL;
- ftruncate(fd, 0);
+ if (ftruncate(fd, 0) < 0)
+ FAIL("ftruncate failed: %s", strerror(errno));
return;
}

@@ -168,13 +170,15 @@ static void test_once(int fd)
if (p == MAP_FAILED)
FAIL("mmap() 1: %s", strerror(errno));

- ftruncate(fd, hpage_size);
+ if (ftruncate(fd, hpage_size) < 0)
+ FAIL("ftruncate failed: %s", strerror(errno));

q = p + hpage_size - COPY_SIZE;

jumpfunc(1, q);

- ftruncate(fd, 0);
+ if (ftruncate(fd, 0) < 0)
+ FAIL("ftruncate failed: %s", strerror(errno));
p = mmap(p, hpage_size, PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_SHARED|MAP_FIXED, fd, 0);
if (p == MAP_FAILED)
--
2.20.1

Eric B Munson

unread,
Aug 19, 2019, 4:56:43 PM8/19/19
to libhug...@googlegroups.com
On Sun, 18 Aug 2019, er...@munsonfam.org wrote:

> From: Eric B Munson <er...@munsonfam.org>
>
> If the system call failes, there isn't any reason to continue with the
> test.
>
> Signed-off-by: Eric B Munson <er...@munsonfam.org>

Applied, thanks
Reply all
Reply to author
Forward
0 new messages