summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-08 05:57:40 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-08 05:57:40 -0700
commitf8a58213b89f054ba620b8772a01d41a6f783d1a (patch)
tree43fba442f8a641ff4d32f56c167491c2f02efbe2
parent3c78e9ea75c2c28bafbc598a6c1c1f615ea63623 (diff)
downloadtxr-f8a58213b89f054ba620b8772a01d41a6f783d1a.tar.gz
txr-f8a58213b89f054ba620b8772a01d41a6f783d1a.tar.bz2
txr-f8a58213b89f054ba620b8772a01d41a6f783d1a.zip
buffers: don't let a buffer shrink to zero.
* buf.c (buf_shrink): If a buffer has zero length, don't shrink the allocation size all the way down to zero, because that value indicates a non-resizeable buffer.
-rw-r--r--buf.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/buf.c b/buf.c
index 5f8f17f8..c9cb4332 100644
--- a/buf.c
+++ b/buf.c
@@ -150,11 +150,13 @@ static void buf_grow(struct buf *b, val init_val, val self)
static void buf_shrink(struct buf *b)
{
- cnum oldsize = c_num(b->size);
- cnum len = c_num(b->len);
+ val len = b->len;
+
+ if (len == zero)
+ len = succ(len);
- if (len != oldsize) {
- b->data = chk_realloc(b->data, len);
+ if (len != b->size) {
+ b->data = chk_realloc(b->data, c_num(len));
b->size = b->len;
}
}