Fix bug when appending buffer to self.

janet_to_string_b had a bug when printing buffers.
This commit is contained in:
Calvin Rose 2019-11-10 14:50:21 -06:00
parent 5681e02e0f
commit 6b76ac3d18
3 changed files with 16 additions and 4 deletions

View File

@ -1,6 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.
### Unreleased
- Fix bug when printing buffer to self in some cases.
## 1.5.0 - 2019-11-10
- `os/date` now defaults to UTC.
- Add `--test` flag to jpm to test libraries on installation.

View File

@ -253,11 +253,13 @@ void janet_to_string_b(JanetBuffer *buffer, Janet x) {
default:
janet_description_b(buffer, x);
break;
case JANET_BUFFER:
janet_buffer_push_bytes(buffer,
janet_unwrap_buffer(x)->data,
janet_unwrap_buffer(x)->count);
case JANET_BUFFER: {
JanetBuffer *to = janet_unwrap_buffer(x);
/* Prevent resizing buffer while appending */
if (buffer == to) janet_buffer_extra(buffer, to->count);
janet_buffer_push_bytes(buffer, to->data, to->count);
break;
}
case JANET_STRING:
case JANET_SYMBOL:
case JANET_KEYWORD:

View File

@ -221,4 +221,11 @@
:week-day 3}
(os/date 1388608200)) "os/date")
# Appending buffer to self
(with-dyns [:out @""]
(prin "abcd")
(prin (dyn :out))
(assert (deep= (dyn :out) @"abcdabcd") "print buffer to self"))
(end-suite)