Back to index

glibc  2.9
Functions | Variables
tst-mcheck.c File Reference
#include <errno.h>
#include <stdio.h>
#include <stdlib.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-mcheck.c.

{
  void *p, *q;

  errno = 0;

  p = malloc (-1);

  if (p != NULL)
    merror ("malloc (-1) succeeded.");
  else if (errno != 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 (p == NULL)
    merror ("malloc (0) failed.");

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

  q = malloc (256);
  if (q == NULL)
    merror ("malloc (256) failed.");

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

  if (realloc (p, -256) != NULL)
    merror ("realloc (p, -256) succeeded.");
  else if (errno != ENOMEM)
    merror ("errno is not set correctly.");

  free (p);

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

  if (realloc (p, -1) != NULL)
    merror ("realloc (p, -1) succeeded.");
  else if (errno != ENOMEM)
    merror ("errno is not set correctly.");

  free (p);
  free (q);

  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-mcheck.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-mcheck.c.