From 795cdfc9abadb7ec4a93e8a01dae7bec1832dcc7 Mon Sep 17 00:00:00 2001 From: Marian Beermann Date: Fri, 2 Jun 2017 19:28:50 +0200 Subject: [PATCH] cache sync: move stat initialization to main unpack --- src/borg/cache_sync/cache_sync.c | 5 +---- src/borg/cache_sync/unpack.h | 15 ++++++++++++++- src/borg/cache_sync/unpack_template.h | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/borg/cache_sync/cache_sync.c b/src/borg/cache_sync/cache_sync.c index 174e4b909..e0c2e0fb8 100644 --- a/src/borg/cache_sync/cache_sync.c +++ b/src/borg/cache_sync/cache_sync.c @@ -19,11 +19,8 @@ cache_sync_init(HashIndex *chunks) } unpack_init(&ctx->ctx); - + /* needs to be set only once */ ctx->ctx.user.chunks = chunks; - ctx->ctx.user.last_error = NULL; - ctx->ctx.user.level = 0; - ctx->ctx.user.inside_chunks = false; ctx->buf = NULL; ctx->head = 0; ctx->tail = 0; diff --git a/src/borg/cache_sync/unpack.h b/src/borg/cache_sync/unpack.h index 0d71a9401..62e775f46 100644 --- a/src/borg/cache_sync/unpack.h +++ b/src/borg/cache_sync/unpack.h @@ -89,6 +89,8 @@ typedef struct unpack_user { expect_csize, /* next thing must be the end of the CLE (array_end) */ expect_entry_end, + + expect_item_begin } expect; struct { @@ -108,6 +110,14 @@ typedef int (*execute_fn)(unpack_context *ctx, const char* data, size_t len, siz return -1; \ } +static inline void unpack_init_user_state(unpack_user *u) +{ + u->last_error = NULL; + u->level = 0; + u->inside_chunks = false; + u->expect = expect_item_begin; +} + static inline int unpack_callback_int64(unpack_user* u, int64_t d) { switch(u->expect) { @@ -282,8 +292,11 @@ static inline int unpack_callback_map(unpack_user* u, unsigned int n) { (void)n; - if(u->level == 0) { + if(u->expect != expect_item_begin) { + set_last_error("Invalid state transition"); /* unreachable */ + return -1; + } /* This begins a new Item */ u->expect = expect_chunks_map_key; } diff --git a/src/borg/cache_sync/unpack_template.h b/src/borg/cache_sync/unpack_template.h index aa7a4c0bb..1ac262740 100644 --- a/src/borg/cache_sync/unpack_template.h +++ b/src/borg/cache_sync/unpack_template.h @@ -42,6 +42,7 @@ static inline void unpack_init(unpack_context* ctx) ctx->cs = CS_HEADER; ctx->trail = 0; ctx->top = 0; + unpack_init_user_state(&ctx->user); } #define construct 1