diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2018-06-23 10:40:11 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2018-06-23 10:40:11 +0300 |
commit | 9b7336575bf6bfa4b2683289308fea2670dfa3e3 (patch) | |
tree | 3c7f05e6aedfd278ecf02a7e0635e4eeb1f425a6 /src | |
parent | e917544c090a960c7904e3ef7b237b113f794ffd (diff) | |
download | gdbm-9b7336575bf6bfa4b2683289308fea2670dfa3e3.tar.gz gdbm-9b7336575bf6bfa4b2683289308fea2670dfa3e3.tar.bz2 |
Maintain correct ordering of the avail table after coalescing.
* src/falloc.c (_gdbm_put_av_elem): Float the merged entry to its
proper position to preserve the sorting order.
* THANKS: Thanks Adam Sampson
Diffstat (limited to 'src')
-rw-r--r-- | src/falloc.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/falloc.c b/src/falloc.c index 6571d9b..2fb8ea1 100644 --- a/src/falloc.c +++ b/src/falloc.c | |||
@@ -424,15 +424,26 @@ _gdbm_put_av_elem (avail_elem new_el, avail_elem av_table[], int *av_count, | |||
424 | /* Not contiguous */ | 424 | /* Not contiguous */ |
425 | else | 425 | else |
426 | { | 426 | { |
427 | index++; | 427 | index++; |
428 | continue; | 428 | continue; |
429 | } | 429 | } |
430 | 430 | ||
431 | /* If we got here, we're done. */ | 431 | /* Coalescing breaks the sorting order, so we need to |
432 | return TRUE; | 432 | restore it */ |
433 | while (index + 1 < *av_count | ||
434 | && av_table[index].av_size > av_table[index + 1].av_size) | ||
435 | { | ||
436 | avail_elem t = av_table[index]; | ||
437 | av_table[index] = av_table[index + 1]; | ||
438 | av_table[index + 1] = t; | ||
439 | index++; | ||
440 | } | ||
441 | |||
442 | /* we're done. */ | ||
443 | return TRUE; | ||
433 | } | 444 | } |
434 | } | 445 | } |
435 | 446 | ||
436 | /* Search for place to put element. List is sorted by size. */ | 447 | /* Search for place to put element. List is sorted by size. */ |
437 | index = 0; | 448 | index = 0; |
438 | while (index < *av_count && av_table[index].av_size < new_el.av_size) | 449 | while (index < *av_count && av_table[index].av_size < new_el.av_size) |