瀏覽代碼

Fix in bitmap-organized raw block; Example and Larson tests now pass

The pointer to be returned was not starting from the proper offset
(raw block address vs. raw block address + sizeof(raw block)).
Ioannis Koutras 12 年之前
父節點
當前提交
9ebf89324f
共有 1 個文件被更改,包括 5 次插入4 次删除
  1. 5 4
      src/bitmap/bitmap_malloc.c

+ 5 - 4
src/bitmap/bitmap_malloc.c

@@ -58,7 +58,6 @@ void * bitmap_malloc(raw_block_header_t *raw_block, size_t req_size) {
         cells = req_size / rb_header->bytes_per_cell;
     }
 
-    // perform bitwise shift & and operations in the BMAP_EL_TYPE arrays
     stop = prev_pow2(cells);
 
 #ifdef HAVE_LOCKS
@@ -66,6 +65,8 @@ void * bitmap_malloc(raw_block_header_t *raw_block, size_t req_size) {
 #endif /* HAVE_LOCKS */
 
     copy_array(temp1, rb_header->bmap_array);
+
+    // perform bitwise shift & and operations in the BMAP_EL_TYPE arrays
     for(i = 1; i < stop; i <<= 1) {
         copy_array(temp2, temp1);
         shift_array(temp2, i);
@@ -78,7 +79,6 @@ void * bitmap_malloc(raw_block_header_t *raw_block, size_t req_size) {
     }
 
     found = 0;
-    ret = NULL;
 
     for(i = 0; i < BMAP_INDEX_NUM; ++i) {
         found = __builtin_ffsl(temp1[i]);
@@ -95,8 +95,9 @@ void * bitmap_malloc(raw_block_header_t *raw_block, size_t req_size) {
                 rb_header->bmap_array[i] &= mask1;
 
             // Calculate the pointer to the chunk to be retrieved
-            chunk_address = (chunk_header_t *)((char *)rb_header + (i *
-                        BMAP_EL_SIZE_BITS + found - 1) *
+            chunk_address = (chunk_header_t *)((char *)rb_header +
+                    sizeof(bitmap_rb_t) +
+                    (i * BMAP_EL_SIZE_BITS + found - 1) *
                     rb_header->bytes_per_cell);
             chunk_address->num_of_cells = cells;