Quellcode durchsuchen

fix bitmap initialization for unused bits in the bitmap vector

Ioannis Koutras vor 12 Jahren
Ursprung
Commit
4edf0866ce
1 geänderte Dateien mit 14 neuen und 16 gelöschten Zeilen
  1. 14 16
      src/raw_block.c

+ 14 - 16
src/raw_block.c

@@ -102,24 +102,22 @@ raw_block_header_t *create_raw_block(size_t raw_block_size, rb_type type) {
             bitmap_p = (BMAP_EL_TYPE *)((char *)bitmap_rb +
                     sizeof(bitmap_rb_t));
             for(size_t i = 0; i < bitmap_rb->elements; ++i) {
-                *bitmap_p = BMAP_EL_INIT_VAL;
-                bitmap_p++;
-            }
-
-            /* If there are some remaining cells, so an extra bitmap vector
-             * element is used, the cells that cannot be used by the
-             * application, have to be set as already used.
-             */
-
-            if(remaining_cells != 0) {
 
-                bitmap_p--;
-
-                for(size_t zeroes = BMAP_EL_SIZE_BITS - remaining_cells;
-                        zeroes > 0; --zeroes) {
-                    *bitmap_p <<= 1;
+                /* If there are some remaining cells, so an extra bitmap vector
+                 * element is used, the cells that cannot be used by the
+                 * application, have to be set as already used.
+                 */
+                if(i == 0 && remaining_cells != 0) {
+                    *bitmap_p = (BMAP_EL_TYPE) 1;
+                    for(size_t ones = remaining_cells - 1;
+                            ones > 0; --ones) {
+                        *bitmap_p <<= 1;
+                        (*bitmap_p)++;
+                    }
+                } else {
+                    *bitmap_p = BMAP_EL_INIT_VAL;
                 }
-
+                bitmap_p++;
             }
 
             break;