mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-19 12:42:31 +02:00
Fixed memory size caluclation problem.
See https://github.com/msgpack/msgpack-c/issues/149
This commit is contained in:
14
src/unpack.c
14
src/unpack.c
@@ -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);
|
||||
|
Reference in New Issue
Block a user