aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2015-07-25 12:43:03 +0300
committerZyX <kp-pav@yandex.ru>2015-10-08 22:00:13 +0300
commitebf3c86a552696df136b94f63c06b6db00155f40 (patch)
tree8a0eb5298c555711f502f0036035c6e8c75d2461
parent83785ef98b90901414f367f592c6132cf5c8a6f3 (diff)
downloadrneovim-ebf3c86a552696df136b94f63c06b6db00155f40.tar.gz
rneovim-ebf3c86a552696df136b94f63c06b6db00155f40.tar.bz2
rneovim-ebf3c86a552696df136b94f63c06b6db00155f40.zip
shada: Handle all possible msgpack_unpacker_next returns
-rw-r--r--src/nvim/shada.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/nvim/shada.c b/src/nvim/shada.c
index a6054db9d0..274296eee4 100644
--- a/src/nvim/shada.c
+++ b/src/nvim/shada.c
@@ -3106,15 +3106,38 @@ shada_read_next_item_start:
msgpack_unpacked unpacked;
msgpack_unpacked_init(&unpacked);
+ bool did_try_to_free = false;
+shada_read_next_item_read_next: {}
const msgpack_unpack_return result =
msgpack_unpacker_next(unpacker, &unpacked);
- if (result != MSGPACK_UNPACK_SUCCESS) {
- if (result == MSGPACK_UNPACK_NOMEM_ERROR) {
+ switch (result) {
+ case MSGPACK_UNPACK_SUCCESS: {
+ break;
+ }
+ case MSGPACK_UNPACK_PARSE_ERROR: {
+ emsgu("Failed to parse ShaDa file due to an error at position %" PRIu64,
+ (uint64_t) initial_fpos);
+ goto shada_read_next_item_error;
+ }
+ case MSGPACK_UNPACK_NOMEM_ERROR: {
+ if (!did_try_to_free) {
+ did_try_to_free = true;
+ try_to_free_memory();
+ goto shada_read_next_item_read_next;
+ }
EMSG(e_outofmem);
goto shada_read_next_item_error;
}
- if (result == MSGPACK_UNPACK_PARSE_ERROR) {
- EMSG("Failed to parse ShaDa file");
+ case MSGPACK_UNPACK_CONTINUE: {
+ emsgu("Failed to parse ShaDa file: incomplete msgpack string "
+ "at position %" PRIu64,
+ (uint64_t) initial_fpos);
+ goto shada_read_next_item_error;
+ }
+ case MSGPACK_UNPACK_EXTRA_BYTES: {
+ emsgu("Failed to parse ShaDa file: extra bytes in msgpack string "
+ "at position %" PRIu64,
+ (uint64_t) initial_fpos);
goto shada_read_next_item_error;
}
}