+int compare_area(void *area1, void* area2, size_t size){
+
+ int distance = 0;
+ int i, pointer_align;
+ void *address_pointed1 = NULL, *address_pointed2 = NULL;
+ int block_pointed1, block_pointed2, frag_pointed1, frag_pointed2;
+ void *addr_block_pointed1 = NULL, *addr_block_pointed2 = NULL, *addr_frag_pointed1 = NULL, *addr_frag_pointed2 = NULL;
+
+ for(i=0; i<size; i++){
+
+ if(memcmp(((char *)area1) + i, ((char *)area2) + i, 1) != 0){
+
+ /* Check pointer difference */
+ pointer_align = (i / sizeof(void*)) * sizeof(void*);
+ address_pointed1 = *((void **)((char *)area1 + pointer_align));
+ address_pointed2 = *((void **)((char *)area2 + pointer_align));
+
+ /* Get pointed blocks number */
+ block_pointed1 = ((char*)address_pointed1 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1;
+ block_pointed2 = ((char*)address_pointed2 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1;
+
+ /* Check if valid blocks number */
+ if((char *)address_pointed1 < (char*)((struct mdesc*)s_heap)->heapbase || block_pointed1 > heapsize1 || block_pointed1 < 1 || (char *)address_pointed2 < (char*)((struct mdesc*)s_heap)->heapbase || block_pointed2 > heapsize2 || block_pointed2 < 1) {
+ fprintf(stderr, "Unknown pointer(s) ! \n");
+ fflush(NULL);
+ distance++;
+ continue;
+ }
+
+ /* Get address of pointed block in saved heaps */
+ addr_block_pointed1 = ((void*) (((ADDR2UINT((size_t)block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
+ addr_block_pointed2 = ((void*) (((ADDR2UINT((size_t)block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
+
+ if(heapinfo1[block_pointed1].type == heapinfo2[block_pointed2].type){ /* Same type of block (large or fragmented) */
+
+ if(heapinfo1[block_pointed1].type == 0){ /* Large block */
+
+ if(heapinfo1[block_pointed1].busy_block.busy_size == heapinfo2[block_pointed2].busy_block.busy_size){
+
+ if(compare_area(addr_block_pointed1, addr_block_pointed2, heapinfo1[block_pointed1].busy_block.busy_size) != 0){
+ /* FIXME : Check temp list of differences */
+ distance++;
+ }else{
+ fprintf(stderr, "False difference detected\n");
+ }
+
+ }else{
+ /* FIXME : Add blocks in temp list of differences */
+ distance++;
+ }
+
+ }else{ /* Fragmented block */
+
+ /* Get pointed fragments number */
+ frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> ((struct mdesc*)s_heap)->heapinfo[block_pointed1].type;
+ frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> ((struct mdesc*)s_heap)->heapinfo[block_pointed2].type;
+
+ /* Get address of pointed fragments in saved heaps */
+ addr_frag_pointed1 = (char*)addr_block_pointed1 + (frag_pointed1 * (int)pow(2, heapinfo1[block_pointed1].type));
+ addr_frag_pointed2 = (char*)addr_block_pointed2 + (frag_pointed2 * (int)pow(2, heapinfo2[block_pointed2].type));
+
+ if(heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1] == heapinfo2[block_pointed2].busy_frag.frag_size[frag_pointed2]){
+
+ if(compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1]) != 0){
+ /* FIXME : Check in temp list of differences */
+ distance++;
+ }else{
+ fprintf(stderr, "False difference detected\n");
+ }
+
+ }else{
+ /* FIXME : Check in temp list of differences */
+ distance ++;
+ }
+
+ }
+
+ }else{ /* Can be fragmented block with different fragments size but same size_used */
+
+ if(((heapinfo1[block_pointed1].type == 0) && (heapinfo2[block_pointed2].type != 0)) || ((heapinfo1[block_pointed1].type != 0) && (heapinfo2[block_pointed2].type == 0))){
+
+ fprintf(stderr, "Pointers on blocks with different types \n");
+ distance++;
+
+ }else{
+
+ /* Get pointed fragments number */
+ frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> ((struct mdesc*)s_heap)->heapinfo[block_pointed1].type;
+ frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> ((struct mdesc*)s_heap)->heapinfo[block_pointed2].type;
+
+ /* Get address of pointed fragments in saved heaps */
+ addr_frag_pointed1 = (char*)addr_block_pointed1 + (frag_pointed1 * (int)pow(2, heapinfo1[block_pointed1].type));
+ addr_frag_pointed2 = (char*)addr_block_pointed2 + (frag_pointed2 * (int)pow(2, heapinfo2[block_pointed2].type));
+
+ if(heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1] == heapinfo2[block_pointed2].busy_frag.frag_size[frag_pointed2]){
+
+ if(compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1]) != 0){
+ /* FIXME : Check temp list of differences */
+ distance++;
+ }else{
+ fprintf(stderr, "False difference detected\n");
+ }
+
+ }else{
+ /* FIXME : Check list of differences */
+ distance ++;
+ }
+
+ }
+
+ }
+ }
+ }
+
+ return distance;
+
+}
+
+