Esempio n. 1
0
void         *
guarded_realloc (void *orig_ptr, size_t length)
{
	char         *ptr = NULL ;

	if (length <= 0)
		length = 1;

#if defined(__CYGWIN__)
	/* lets do some magic with Win32 memory allocation to test for memory corruption : */
	ptr = alloc_guarded_memory( length );	   
	if( orig_ptr && ptr ) 
	{
		size_t old_size = get_guarded_memory_size( orig_ptr );	
		if( length < old_size ) 
		{	
#ifdef LOCAL_DEBUG			
			fprintf( stderr, "ALLOC: trying to reallocate memory from %d bytes to %d bytes - truncating.\n", old_size, length );
#endif			
			old_size = length;
		}
		memcpy( ptr, orig_ptr, old_size );
		free_guarded_memory( orig_ptr );
	}
#else
	ptr = realloc (orig_ptr, length);
#endif

	if (ptr == (char *)0)
		failed_alloc( "guarded_realloc", length );
	
	return ptr;
}
Esempio n. 2
0
void         *
saferealloc (void *orig_ptr, size_t length)
{
#if defined(__CYGWIN__) && defined(DEBUG_ALLOCS) && !defined(NOGUARD)
	return guarded_realloc( orig_ptr, length );
#else
	char         *ptr = NULL ;

	if (length <= 0)
		length = 1;

	ptr = realloc (orig_ptr, length);

	if (ptr == (char *)0)
		failed_alloc( "realloc", length );
	
	return ptr;
#endif
}
Esempio n. 3
0
void         *
safecalloc (size_t num, size_t blength)
{
#if defined(__CYGWIN__) && defined(DEBUG_ALLOCS) && !defined(NOGUARD)
	return guarded_calloc( num, blength );
#else
	char         *ptr;

    if (blength <= 0)
        blength = 1;
    
	if (num <= 0)
        num = 1;

	ptr = calloc (num, blength);
	if (ptr == (char *)0)
		failed_alloc( "calloc", num*blength );
	return ptr;
#endif
}
Esempio n. 4
0
void         *
guarded_malloc (size_t length)
{
	char         *ptr = NULL ;

	if (length <= 0)
		length = 1;

#if defined(__CYGWIN__)
	/* lets do some magic with Win32 memory allocation to test for memory corruption : */
	ptr = alloc_guarded_memory( length );	   
#else
	ptr = malloc (length);
#endif

	if (ptr == (char *)0)
		failed_alloc( "malloc", length );
	
	return ptr;
}
Esempio n. 5
0
void         *
guarded_calloc (size_t num, size_t blength)
{
	char         *ptr;

    if (blength <= 0)
        blength = 1;
    
	if (num <= 0)
        num = 1;

#if defined(__CYGWIN__)
	ptr = alloc_guarded_memory( num * blength );	   
	if(ptr)
		memset( ptr, 0x00, num*blength );
#else    
	ptr = calloc (num, blength);
#endif

	if (ptr == (char *)0)
		failed_alloc( "guarded_calloc", num*blength );
	return ptr;
}
Esempio n. 6
0
int		load_lights(t_bunny_ini *ini, t_rtracer *data)
{
  const char	*extract;
  int		rounds;
  int		i;

  if ((extract = bunny_ini_get_field(ini, "light", "nb", 0)) == NULL)
    {
      data->nb_lights = 0;
      return (0);
    }
  rounds = my_getnbr(extract);
  if ((data->lights = bunny_malloc(sizeof(t_figure) * rounds)) == NULL)
    return (failed_alloc());
  data->nb_lights = rounds;
  i = 0;
  while (i < rounds)
    {
      if (add_one_light(&data->lights[i], ini, i, rounds) == - 1)
	return (-1);
      i++;
    }
  return (0);
}