Home | History | Annotate | Download | only in tests
      1 
      2 /* test of plausible behaviour with malloc and stupid args */
      3 
      4 #include <stdlib.h>
      5 #include <stdio.h>
      6 
      7 int main ( void )
      8 {
      9   char* p;
     10 
     11   p = malloc(0);
     12   printf("malloc(0) = 0x%lx\n", (unsigned long)p);
     13   free(p);
     14 
     15   p = malloc(-1);
     16   printf("malloc(-1) = 0x%lx\n", (unsigned long)p);
     17   free(p);
     18 
     19   p = calloc(0,1);
     20   printf("calloc(0,1) = 0x%lx\n", (unsigned long)p);
     21   free(p);
     22 
     23   p = calloc(0,-1);
     24   printf("calloc(0,-1) = 0x%lx\n", (unsigned long)p);
     25   free(p);
     26 
     27   // We no longer get a warning with this due to the calloc overflow checking
     28   // done for bug 149878.  It's no great loss, it's extremely unlikely to
     29   // occur in practice.
     30   p = calloc(-1,-1);
     31   printf("calloc(-1,-1) = 0x%lx\n", (unsigned long)p);
     32   free(p);
     33 
     34   return 0;
     35 }
     36