Esempio n. 1
0
void *
tests_reallocate (void *ptr, size_t old_size, size_t new_size)
{
    struct header  **hp, *h;

    if (new_size == 0)
    {
        printf ("tests_reallocate(): attempt to reallocate 0x%lX to 0 bytes\n",
                (unsigned long) ptr);
        abort ();
    }

    hp = tests_memory_find (ptr);
    if (hp == NULL)
    {
        printf ("tests_reallocate(): attempt to reallocate bad pointer 0x%lX\n",
                (unsigned long) ptr);
        abort ();
    }
    h = *hp;

    if (h->size != old_size)
    {
        /* Note: we should use the standard %zu to print sizes, but
           this is not supported by old C implementations. */
        printf ("tests_reallocate(): bad old size %lu, should be %lu\n",
                (unsigned long) old_size, (unsigned long) h->size);
        abort ();
    }

    h->size = new_size;
    h->ptr = __gmp_default_reallocate (ptr, old_size, new_size);
    return h->ptr;
}
Esempio n. 2
0
void *
tests_reallocate (void *ptr, size_t old_size, size_t new_size)
{
  struct header  **hp, *h;
  void *rptr;
  mp_limb_t PATTERN2_var;

  if (new_size == 0)
    {
      fprintf (stderr, "tests_reallocate(): attempt to reallocate %p to 0 bytes\n",
	       ptr);
      abort ();
    }

  hp = tests_memory_find (ptr);
  if (hp == NULL)
    {
      fprintf (stderr, "tests_reallocate(): attempt to reallocate bad pointer %p\n",
	       ptr);
      abort ();
    }
  h = *hp;

  if (h->size != old_size)
    {
      fprintf (stderr, "tests_reallocate(): bad old size %lu, should be %lu\n",
	       (unsigned long) old_size, (unsigned long) h->size);
      abort ();
    }

  if (*((mp_limb_t *) ((gmp_intptr_t) ptr - sizeof (mp_limb_t)))
      != PATTERN1 - PTRLIMB (ptr))
    {
      fprintf (stderr, "in realloc: redzone clobbered before block\n");
      abort ();
    }
  PATTERN2_var = PATTERN2 - PTRLIMB (ptr);
  if (memcmp ((void *) ((gmp_intptr_t) ptr + h->size), &PATTERN2_var, sizeof (mp_limb_t)))
    {
      fprintf (stderr, "in realloc: redzone clobbered after block\n");
      abort ();
    }

  rptr = __gmp_default_reallocate ((void *) ((gmp_intptr_t) ptr - sizeof (mp_limb_t)),
				 old_size + 2 * sizeof (mp_limb_t),
				 new_size + 2 * sizeof (mp_limb_t));
  ptr = (void *) ((gmp_intptr_t) rptr + sizeof (mp_limb_t));

  *((mp_limb_t *) ((gmp_intptr_t) ptr - sizeof (mp_limb_t)))
    = PATTERN1 - PTRLIMB (ptr);
  PATTERN2_var = PATTERN2 - PTRLIMB (ptr);
  memcpy ((void *) ((gmp_intptr_t) ptr + new_size), &PATTERN2_var, sizeof (mp_limb_t));

  h->size = new_size;
  h->ptr = ptr;
  return h->ptr;
}
Esempio n. 3
0
int
tests_memory_valid (void *ptr)
{
  return (tests_memory_find (ptr) != NULL);
}