mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Avoid void pointer arithmetic in halloc.c
darcs-hash:20070908191814-ac50b-bb024c5a7ee878810bc7e12dcbcce32ff0145090.gz
This commit is contained in:
parent
5a61ae3e0d
commit
38ed4c0f9b
1 changed files with 9 additions and 9 deletions
16
halloc.c
16
halloc.c
|
@ -70,7 +70,7 @@ typedef struct halloc
|
||||||
/**
|
/**
|
||||||
Memory scratch area used to fullfil smaller memory allocations
|
Memory scratch area used to fullfil smaller memory allocations
|
||||||
*/
|
*/
|
||||||
void *scratch;
|
char *scratch;
|
||||||
/**
|
/**
|
||||||
Amount of free space in the scratch area
|
Amount of free space in the scratch area
|
||||||
*/
|
*/
|
||||||
|
@ -78,13 +78,13 @@ typedef struct halloc
|
||||||
}
|
}
|
||||||
halloc_t;
|
halloc_t;
|
||||||
|
|
||||||
static void *align_ptr( void *in )
|
static char *align_ptr( char *in )
|
||||||
{
|
{
|
||||||
unsigned long step = maxi(sizeof(double),sizeof(void *));
|
unsigned long step = maxi(sizeof(double),sizeof(void *));
|
||||||
unsigned long inc = step-1;
|
unsigned long inc = step-1;
|
||||||
unsigned long long_in = (long)in;
|
unsigned long long_in = (long)in;
|
||||||
unsigned long long_out = ((long_in+inc)/step)*step;
|
unsigned long long_out = ((long_in+inc)/step)*step;
|
||||||
return (void *)long_out;
|
return (char *)long_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t align_sz( size_t in )
|
static size_t align_sz( size_t in )
|
||||||
|
@ -132,8 +132,8 @@ void *halloc( void *context, size_t size )
|
||||||
halloc_t *me, *parent;
|
halloc_t *me, *parent;
|
||||||
if( context )
|
if( context )
|
||||||
{
|
{
|
||||||
void *res;
|
char *res;
|
||||||
void *aligned;
|
char *aligned;
|
||||||
|
|
||||||
#ifdef HALLOC_DEBUG
|
#ifdef HALLOC_DEBUG
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ void *halloc( void *context, size_t size )
|
||||||
if( !res )
|
if( !res )
|
||||||
DIE_MEM();
|
DIE_MEM();
|
||||||
}
|
}
|
||||||
al_push( &parent->children, &late_free );
|
al_push_func( &parent->children, &late_free );
|
||||||
al_push( &parent->children, res );
|
al_push( &parent->children, res );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ void halloc_register_function( void *context, void (*func)(void *), void *data )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
me = halloc_from_data( context );
|
me = halloc_from_data( context );
|
||||||
al_push( &me->children, func );
|
al_push_func( &me->children, func );
|
||||||
al_push( &me->children, data );
|
al_push( &me->children, data );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ void halloc_free( void *context )
|
||||||
}
|
}
|
||||||
for( i=0; i<al_get_count(&me->children); i+=2 )
|
for( i=0; i<al_get_count(&me->children); i+=2 )
|
||||||
{
|
{
|
||||||
void (*func)(void *) = (void (*)(void *))al_get( &me->children, i );
|
void (*func)(void *) = (void (*)(void *))al_get_func( &me->children, i );
|
||||||
void * data = (void *)al_get( &me->children, i+1 );
|
void * data = (void *)al_get( &me->children, i+1 );
|
||||||
if( func == &late_free )
|
if( func == &late_free )
|
||||||
free( data );
|
free( data );
|
||||||
|
|
Loading…
Reference in a new issue