Back to index

glibc  2.9
Functions | Variables
tst-malloc.c File Reference
#include <errno.h>
#include <malloc.h>
#include <stdio.h>

Go to the source code of this file.

Functions

static void merror (const char *msg)
int main (void)

Variables

static int errors = 0

Function Documentation

int main ( void  )

Definition at line 34 of file tst-malloc.c.

{
  void *p, *q;
  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.");

  /* realloc (p, 0) == free (p).  */
  p = realloc (p, 0);
  if (p != NULL)
    merror ("realloc (p, 0) failed.");

  p = malloc (0);
  if (p == NULL)
    merror ("malloc (0) failed.");

  p = realloc (p, 0);
  if (p != NULL)
    merror ("realloc (p, 0) failed.");

  p = malloc (513 * 1024);
  if (p == NULL)
    merror ("malloc (513K) failed.");

  q = malloc (-512 * 1024);
  if (q != NULL)
    merror ("malloc (-512K) succeeded.");

  free (p);

  return errors != 0;
}

Here is the call graph for this function:

static void merror ( const char *  msg) [static]

Definition at line 27 of file tst-malloc.c.

{
  ++errors;
  printf ("Error: %s\n", msg);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int errors = 0 [static]

Definition at line 24 of file tst-malloc.c.