Commit 1e2394cf authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(join_range): Fixed a bug where a pointer that pointed to the old

	position of a reallocated block was used.
parent a68a020e
...@@ -404,17 +404,18 @@ join_range(Local_to_global *l2g, ...@@ -404,17 +404,18 @@ join_range(Local_to_global *l2g,
while (binfo < l2g->blocks + l2g->num_blocks) while (binfo < l2g->blocks + l2g->num_blocks)
{ {
assert(binfo - (last - first) > first);
*(binfo - (last - first)) = *binfo; *(binfo - (last - first)) = *binfo;
++binfo; ++binfo;
} }
l2g->num_blocks -= last - first;
l2g->blocks = srealloc(l2g->blocks,
l2g->num_blocks * sizeof(struct l2g_block_info));
assert(next <= L2G_BLOCKSIZE); assert(next <= L2G_BLOCKSIZE);
first->first_free = next; first->first_free = next;
first->zeroes = L2G_BLOCKSIZE - next; first->zeroes = L2G_BLOCKSIZE - next;
l2g->num_blocks -= last - first;
l2g->blocks = srealloc(l2g->blocks,
l2g->num_blocks * sizeof(struct l2g_block_info));
} }
...@@ -790,60 +791,55 @@ l2g_delete_global_in_sorted(Local_to_global *l2g, ...@@ -790,60 +791,55 @@ l2g_delete_global_in_sorted(Local_to_global *l2g,
for (l2gi_searchall(&iter, l2g); !iter.search_ended; l2gi_next(&iter)) for (l2gi_searchall(&iter, l2g); !iter.search_ended; l2gi_next(&iter))
if (iter.tno == tno) if (iter.tno == tno)
{ {
l2g_delete(l2g, iter.lno); L;
return; binfo->value_block = smalloc(L2G_BLOCKSIZE * sizeof(Text_no));
}
#ifndef NDEBUG
for (i = 0; i < L2G_BLOCKSIZE; ++i)
binfo->value_block[i] = 0xdeadbeef;
#endif
return binfo;
} }
/* /*
* Dump the internal structure of L2G onto the file FILE. * Delete a block from the Local_to_global L2G. The pointer BINFO
* points at the block, which is supposed to be empty.
*/ */
void static void
l2g_dump(FILE *file, delete_block(Local_to_global *l2g,
const Local_to_global *l2g) struct l2g_block_info *binfo)
{ {
struct l2g_block_info * binfo; assert(is_empty(binfo));
int i, j;
fprintf(file, "Number of blocks: %d\n", l2g->num_blocks);
fprintf(file, "First unused: %lu\n", l2g->first_unused);
binfo = l2g->blocks; /* Remove the blocks from the Block Info */
for (i = 0; i < l2g->num_blocks; ++i) { if (binfo->key_block != NULL)
fprintf(file, "%d: %d %d %d (%s) [", i, sfree(binfo->key_block);
binfo->first_free, sfree(binfo->value_block);
binfo->zeroes,
(int) binfo->start,
(is_dense(binfo) ? "dense" : "sparse"));
if (is_dense(binfo)) {
for (j = 0; j < binfo->first_free; ++j) {
fprintf(file, "%d ", (int) binfo->value_block[j]);
}
} else {
for (j = 0; j < binfo->first_free; ++j) {
fprintf(file, "%d:%d ",
(int) binfo->key_block[j],
(int) binfo->value_block[j]);
}
}
fprintf(file, "]\n");
binfo++; /* Compact the remaining blocks. */
} while (++binfo < l2g->blocks + l2g->num_blocks)
*(binfo - 1) = *binfo;
l2g->num_blocks--;
l2g->blocks = srealloc(l2g->blocks,
l2g->num_blocks * sizeof(struct l2g_block_info));
} }
/* /*
* Read a Local to global structure from the file FILE. * Make a sparse block from a dense one.
*/ */
static void
Success make_sparse(struct l2g_block_info *binfo)
l2g_read(FILE *fp, Local_to_global *l2g)
{ {
int c; int next;
int i;
assert(is_dense(binfo));
/* Allocate the room for the key bl int c;
Local_text_no lno; Local_text_no lno;
Text_no tno; Text_no tno;
Local_text_no first_unused; Local_text_no first_unused;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment