summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2018-06-23 07:40:11 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2018-06-23 07:40:11 (GMT)
commit9b7336575bf6bfa4b2683289308fea2670dfa3e3 (patch) (side-by-side diff)
tree3c7f05e6aedfd278ecf02a7e0635e4eeb1f425a6
parente917544c090a960c7904e3ef7b237b113f794ffd (diff)
downloadgdbm-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 (more/less context) (ignore whitespace changes)
-rw-r--r--THANKS1
-rw-r--r--src/falloc.c17
2 files changed, 15 insertions, 3 deletions
diff --git a/THANKS b/THANKS
index 444df86..081f753 100644
--- a/THANKS
+++ b/THANKS
@@ -4,6 +4,7 @@ Many people further contributed to GDBM by reporting problems,
suggesting various improvements or submitting actual code. Here is a list
of these people. Help us keep it complete and exempt of errors.
+Adam Sampson <ats@offog.org>
Bill Jones <rj7252@att.com>
Craig Young <csy@ecraig.com>
Jakub Bogusz <qboosh@pld-linux.org>
diff --git a/src/falloc.c b/src/falloc.c
index 6571d9b..2fb8ea1 100644
--- a/src/falloc.c
+++ b/src/falloc.c
@@ -427,9 +427,20 @@ _gdbm_put_av_elem (avail_elem new_el, avail_elem av_table[], int *av_count,
index++;
continue;
}
-
- /* If we got here, we're done. */
- return TRUE;
+
+ /* Coalescing breaks the sorting order, so we need to
+ restore it */
+ while (index + 1 < *av_count
+ && av_table[index].av_size > av_table[index + 1].av_size)
+ {
+ avail_elem t = av_table[index];
+ av_table[index] = av_table[index + 1];
+ av_table[index + 1] = t;
+ index++;
+ }
+
+ /* we're done. */
+ return TRUE;
}
}

Return to:

Send suggestions and report system problems to the System administrator.