Skip to content

Commit

Permalink
Merge pull request #185 from bajamircea/master
Browse files Browse the repository at this point in the history
Fix one more memory size calculation.
  • Loading branch information
redboltz committed Jan 6, 2015
2 parents bf8c830 + 7e59777 commit a84f444
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion include/msgpack/unpack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char*>(::malloc(next_size));
Expand Down

0 comments on commit a84f444

Please sign in to comment.