aboutsummaryrefslogtreecommitdiff
path: root/malloc/tst-pvalloc.c
diff options
context:
space:
mode:
authorWill Newton <will.newton@linaro.org>2013-10-03 11:24:38 +0100
committerWill Newton <will.newton@linaro.org>2013-10-04 09:15:33 +0100
commit1bc92709f336f8f7d5cc3e47a0fec654f57382fe (patch)
treef1069c17c8368ac4307da993cd0b02d38871a38b /malloc/tst-pvalloc.c
parent27d0461b7bb00e8863dbb2087ce22bf67f9c1018 (diff)
downloadglibc-1bc92709f336f8f7d5cc3e47a0fec654f57382fe.tar
glibc-1bc92709f336f8f7d5cc3e47a0fec654f57382fe.tar.gz
glibc-1bc92709f336f8f7d5cc3e47a0fec654f57382fe.tar.bz2
glibc-1bc92709f336f8f7d5cc3e47a0fec654f57382fe.zip
malloc/tst-pvalloc.c: Tidy up code.
Add some comments and call free on all potentially allocated pointers. Also remove duplicate check for NULL pointer. ChangeLog: 2013-10-04 Will Newton <will.newton@linaro.org> * malloc/tst-pvalloc.c: Add comments. (do_test): Add comments and call free on all potentially allocated pointers. Remove duplicate check for NULL pointer. Add space after cast.
Diffstat (limited to 'malloc/tst-pvalloc.c')
-rw-r--r--malloc/tst-pvalloc.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/malloc/tst-pvalloc.c b/malloc/tst-pvalloc.c
index 1126672bd4..1c81294926 100644
--- a/malloc/tst-pvalloc.c
+++ b/malloc/tst-pvalloc.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2013 Free Software Foundation, Inc.
+/* Test for pvalloc.
+ Copyright (C) 2013 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -34,12 +35,14 @@ static int
do_test (void)
{
void *p;
- unsigned long pagesize = getpagesize();
+ unsigned long pagesize = getpagesize ();
unsigned long ptrval;
int save;
errno = 0;
+ /* An attempt to allocate a huge value should return NULL and set
+ errno to ENOMEM. */
p = pvalloc (-1);
save = errno;
@@ -50,8 +53,11 @@ do_test (void)
if (p == NULL && save != ENOMEM)
merror ("pvalloc (-1) errno is not set correctly");
+ free (p);
+
errno = 0;
+ /* Test to expose integer overflow in malloc internals from BZ #15855. */
p = pvalloc (-pagesize);
save = errno;
@@ -62,6 +68,10 @@ do_test (void)
if (p == NULL && save != ENOMEM)
merror ("pvalloc (-pagesize) errno is not set correctly");
+ free (p);
+
+ /* A zero-sized allocation should succeed with glibc, returning a
+ non-NULL value. */
p = pvalloc (0);
if (p == NULL)
@@ -69,15 +79,13 @@ do_test (void)
free (p);
+ /* Check the alignment of the returned pointer is correct. */
p = pvalloc (32);
if (p == NULL)
merror ("pvalloc (32) failed.");
- ptrval = (unsigned long)p;
-
- if (p == NULL)
- merror ("pvalloc (32) failed.");
+ ptrval = (unsigned long) p;
if ((ptrval & (pagesize - 1)) != 0)
merror ("returned pointer is not page aligned.");