From 7e597779e4e9e080b6f41e59c1d20b8b48e9a507 Mon Sep 17 00:00:00 2001 From: Mircea Baja Date: Mon, 5 Jan 2015 21:55:57 +0000 Subject: [PATCH] Fix one more memory size calculation. See https://github.com/msgpack/msgpack-c/issues/149 and the commit d6cc5494a9dd25fe640c1602cdf1b566690c9ba7 --- include/msgpack/unpack.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/msgpack/unpack.hpp b/include/msgpack/unpack.hpp index 67c78713..fd6a4248 100644 --- a/include/msgpack/unpack.hpp +++ b/include/msgpack/unpack.hpp @@ -1262,7 +1262,12 @@ inline void unpacker::expand_buffer(std::size_t size) std::size_t next_size = m_initial_buffer_size; // include COUNTER_SIZE std::size_t not_parsed = m_used - m_off; while(next_size < size + not_parsed + COUNTER_SIZE) { - next_size *= 2; + std::size_t tmp_next_size = next_size * 2; + if (tmp_next_size <= next_size) { + next_size = size + not_parsed + COUNTER_SIZE; + break; + } + next_size = tmp_next_size; } char* tmp = static_cast(::malloc(next_size));