Skip to content

Commit a84f444

Browse files
committed
Merge pull request #185 from bajamircea/master
Fix one more memory size calculation.
2 parents bf8c830 + 7e59777 commit a84f444

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

include/msgpack/unpack.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,12 @@ inline void unpacker::expand_buffer(std::size_t size)
12621262
std::size_t next_size = m_initial_buffer_size; // include COUNTER_SIZE
12631263
std::size_t not_parsed = m_used - m_off;
12641264
while(next_size < size + not_parsed + COUNTER_SIZE) {
1265-
next_size *= 2;
1265+
std::size_t tmp_next_size = next_size * 2;
1266+
if (tmp_next_size <= next_size) {
1267+
next_size = size + not_parsed + COUNTER_SIZE;
1268+
break;
1269+
}
1270+
next_size = tmp_next_size;
12661271
}
12671272

12681273
char* tmp = static_cast<char*>(::malloc(next_size));

0 commit comments

Comments
 (0)