(do_test): Add comments and call free on all potentially
allocated pointers. Add space after cast.
+ * 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.
+
2013-10-04 Alan Modra <amodra@gmail.com>
* sysdeps/powerpc/powerpc32/dl-machine.c (__process_machine_rela):
-/* 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
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;
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;
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)
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.");