@@ -9,7 +9,7 @@ struct alloc_pool
99 size_t size ; /* extent size */
1010 size_t quantum ; /* allocation quantum */
1111 struct pool_extent * extents ; /* top extent is "live" */
12- void (* bomb )(); /* called if malloc fails */
12+ void (* bomb )(const char * , const char * , int ); /* called if malloc fails */
1313 int flags ;
1414
1515 /* statistical data */
@@ -42,6 +42,7 @@ struct align_test {
4242/* Temporarily cast a void* var into a char* var when adding an offset (to
4343 * keep some compilers from complaining about the pointer arithmetic). */
4444#define PTR_ADD (b ,o ) ( (void*) ((char*)(b) + (o)) )
45+ #define PTR_SUB (b ,o ) ( (void*) ((char*)(b) - (o)) )
4546
4647alloc_pool_t
4748pool_create (size_t size , size_t quantum , void (* bomb )(const char * , const char * , int ), int flags )
@@ -100,7 +101,7 @@ pool_destroy(alloc_pool_t p)
100101 for (cur = pool -> extents ; cur ; cur = next ) {
101102 next = cur -> next ;
102103 if (pool -> flags & POOL_PREPEND )
103- free (PTR_ADD (cur -> start , - sizeof (struct pool_extent )));
104+ free (PTR_SUB (cur -> start , sizeof (struct pool_extent )));
104105 else {
105106 free (cur -> start );
106107 free (cur );
@@ -235,7 +236,7 @@ pool_free(alloc_pool_t p, size_t len, void *addr)
235236 if (cur -> free + cur -> bound >= pool -> size ) {
236237 prev -> next = cur -> next ;
237238 if (pool -> flags & POOL_PREPEND )
238- free (PTR_ADD (cur -> start , - sizeof (struct pool_extent )));
239+ free (PTR_SUB (cur -> start , sizeof (struct pool_extent )));
239240 else {
240241 free (cur -> start );
241242 free (cur );
@@ -292,7 +293,7 @@ pool_free_old(alloc_pool_t p, void *addr)
292293 while ((cur = next ) != NULL ) {
293294 next = cur -> next ;
294295 if (pool -> flags & POOL_PREPEND )
295- free (PTR_ADD (cur -> start , - sizeof (struct pool_extent )));
296+ free (PTR_SUB (cur -> start , sizeof (struct pool_extent )));
296297 else {
297298 free (cur -> start );
298299 free (cur );
0 commit comments