Skip to content

Commit 677e6b8

Browse files
authored
Merge pull request #389 from msgpack/str-limit
Don't pre-allocate strings larger than the buffered size
2 parents f0b6281 + 8ba8702 commit 677e6b8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

ext/msgpack/unpacker.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ static int read_raw_body_cont(msgpack_unpacker_t* uk)
336336
size_t length = uk->reading_raw_remaining;
337337

338338
if(uk->reading_raw == Qnil) {
339-
uk->reading_raw = rb_str_buf_new(length);
339+
size_t buffered_size = msgpack_buffer_all_readable_size(UNPACKER_BUFFER_(uk));
340+
uk->reading_raw = rb_str_buf_new(length > buffered_size ? buffered_size : length);
340341
}
341342

342343
do {

0 commit comments

Comments
 (0)