123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include <errno.h>
- #include <malloc.h>
- #include <stdio.h>
- #include <features.h>
- static int errors = 0;
- static void
- merror (const char *msg)
- {
- ++errors;
- printf ("Error: %s\n", msg);
- }
- int
- main (void)
- {
- void *p;
- int save;
- errno = 0;
- p = malloc (-1);
- save = errno;
- if (p != NULL)
- merror ("malloc (-1) succeeded.");
- if (p == NULL && save != ENOMEM)
- merror ("errno is not set correctly");
- p = malloc (10);
- if (p == NULL)
- merror ("malloc (10) failed.");
-
- p = realloc (p, 0);
- if (p != NULL)
- merror ("realloc (p, 0) failed.");
- p = malloc (0);
- #if !defined(__UCLIBC__) || defined(__MALLOC_GLIBC_COMPAT__)
- if (p == NULL)
- #else
- if (p != NULL)
- #endif
- merror ("malloc (0) failed.");
- p = realloc (p, 0);
- if (p != NULL)
- merror ("realloc (p, 0) failed.");
- return errors != 0;
- }
|