aboutsummaryrefslogtreecommitdiff
path: root/tests/mremap-fixed-huge-near-normal.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mremap-fixed-huge-near-normal.c')
-rw-r--r--tests/mremap-fixed-huge-near-normal.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/tests/mremap-fixed-huge-near-normal.c b/tests/mremap-fixed-huge-near-normal.c
index 2c41813..e0f2ae4 100644
--- a/tests/mremap-fixed-huge-near-normal.c
+++ b/tests/mremap-fixed-huge-near-normal.c
@@ -87,6 +87,7 @@ void do_remap(int fd, void *target)
void *map_align(size_t size, size_t align)
{
unsigned long xsize = size + align - getpagesize();
+ size_t t;
void *p, *q;
int rc;
@@ -97,14 +98,19 @@ void *map_align(size_t size, size_t align)
q = PALIGN(p, align);
- rc = munmap(p, q-p);
- if (rc != 0)
- FAIL("munmap(lower aligning): %s", strerror(errno));
-
- rc = munmap(q + size, p + xsize - (q + size));
- if (rc != 0)
- FAIL("munmap(upper aligning): %s", strerror(errno));
+ t = q - p;
+ if (t) {
+ rc = munmap(p, t);
+ if (rc != 0)
+ FAIL("munmap(lower aligning): %s", strerror(errno));
+ }
+ t = p + xsize - (q + size);
+ if (t) {
+ rc = munmap(q + size, t);
+ if (rc != 0)
+ FAIL("munmap(upper aligning): %s", strerror(errno));
+ }
return q;
}