Fixed memory size caluclation problem.

See https://github.com/msgpack/msgpack-c/issues/149
This commit is contained in:
Takatoshi Kondo
2014-11-01 19:41:47 +09:00
parent 96c688708c
commit d6cc5494a9
10 changed files with 70 additions and 13 deletions

View File

@@ -396,7 +396,12 @@ bool msgpack_unpacker_expand_buffer(msgpack_unpacker* mpac, size_t size)
if(mpac->off == COUNTER_SIZE) {
size_t next_size = (mpac->used + mpac->free) * 2; // include COUNTER_SIZE
while(next_size < size + mpac->used) {
next_size *= 2;
size_t tmp_next_size = next_size * 2;
if (tmp_next_size <= next_size) {
next_size = size + mpac->used;
break;
}
next_size = tmp_next_size;
}
char* tmp = (char*)realloc(mpac->buffer, next_size);
@@ -411,7 +416,12 @@ bool msgpack_unpacker_expand_buffer(msgpack_unpacker* mpac, size_t size)
size_t next_size = mpac->initial_buffer_size; // include COUNTER_SIZE
size_t not_parsed = mpac->used - mpac->off;
while(next_size < size + not_parsed + COUNTER_SIZE) {
next_size *= 2;
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 = (char*)malloc(next_size);