tst-mcheck.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Copyright (C) 2005 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Jakub Jelinek <jakub@redhat.com>, 2005.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <errno.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <features.h>
  20. static int errors = 0;
  21. static void
  22. merror (const char *msg)
  23. {
  24. ++errors;
  25. printf ("Error: %s\n", msg);
  26. }
  27. int
  28. main (void)
  29. {
  30. void *p, *q;
  31. errno = 0;
  32. p = malloc (-1);
  33. if (p != NULL)
  34. merror ("malloc (-1) succeeded.");
  35. else if (errno != ENOMEM)
  36. merror ("errno is not set correctly.");
  37. p = malloc (10);
  38. if (p == NULL)
  39. merror ("malloc (10) failed.");
  40. p = realloc (p, 0);
  41. if (p != NULL)
  42. merror ("realloc (p, 0) failed.");
  43. p = malloc (0);
  44. #if !defined(__UCLIBC__) || defined(__MALLOC_GLIBC_COMPAT__)
  45. if (p == NULL)
  46. #else
  47. if (p != NULL)
  48. #endif
  49. merror ("malloc (0) failed.");
  50. p = realloc (p, 0);
  51. if (p != NULL)
  52. merror ("realloc (p, 0) failed.");
  53. q = malloc (256);
  54. if (q == NULL)
  55. merror ("malloc (256) failed.");
  56. p = malloc (512);
  57. if (p == NULL)
  58. merror ("malloc (512) failed.");
  59. if (realloc (p, -256) != NULL)
  60. merror ("realloc (p, -256) succeeded.");
  61. else if (errno != ENOMEM)
  62. merror ("errno is not set correctly.");
  63. free (p);
  64. p = malloc (512);
  65. if (p == NULL)
  66. merror ("malloc (512) failed.");
  67. if (realloc (p, -1) != NULL)
  68. merror ("realloc (p, -1) succeeded.");
  69. else if (errno != ENOMEM)
  70. merror ("errno is not set correctly.");
  71. free (p);
  72. free (q);
  73. return errors != 0;
  74. }