int main(void){ //Main for creation of executable int* arr = (int *) malloc(sizeof(int) * 10); arr = (int *)arealloc(arr,ULONG_MAX,ULONG_MAX); //Since size_t is 64 bit we use ULONG_MAX to create the overlow if(arr==NULL) //Test to check for the correct implementation of arealloc { printf("SUCCESS\n"); } else { printf("FAIL\n"); } return 0; }
struct graph_edge *graph_node_add_edge (struct graph_node *node, struct graph_node *target, sexpr label) { static struct memory_pool pool = MEMORY_POOL_INITIALISER(sizeof (struct graph_edge)); struct graph_edge *edge = (struct graph_edge *) get_pool_mem(&pool); unsigned int size_before = get_chunked_edge_size (node->edge_count), size_after = get_chunked_edge_size (node->edge_count + 1); if (size_before != size_after) { node->edges = (struct graph_edge **) arealloc (size_before, node->edges, size_after); } edge->target = target; edge->label = label; node->edges[node->edge_count] = edge; node->edge_count++; return edge; }
struct graph_node *graph_add_node(sexpr sx, sexpr label) { struct graph *gr = (struct graph *)sx_pointer(sx); static struct memory_pool pool = MEMORY_POOL_INITIALISER(sizeof (struct graph_node)); struct graph_node *node = (struct graph_node *) get_pool_mem(&pool); unsigned int size_before = get_chunked_node_size (gr->node_count), size_after = get_chunked_node_size (gr->node_count + 1); if (size_before != size_after) { gr->nodes = (struct graph_node **) arealloc (size_before, gr->nodes, size_after); } node->edge_count = 0; node->edges = (struct graph_edge **)aalloc (get_chunked_edge_size(0)); node->label = label; gr->nodes[gr->node_count] = node; gr->node_count++; return node; }
/* * MemRealloc - reallocate a block */ ALLOCPTR MemRealloc( ALLOCPTR ptr, unsigned newsize ) { return( arealloc( ptr, newsize ) ); } /* MemRealloc */