From 56f6521cba8ecf74bc85beed7aa9cf82ad5d839f Mon Sep 17 00:00:00 2001 From: Willem Thiart Date: Fri, 29 Jan 2016 15:03:19 +0200 Subject: [PATCH] Prepare log_get_from_idx for log compaction --- src/raft_log.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/raft_log.c b/src/raft_log.c index decad38f..4f148560 100644 --- a/src/raft_log.c +++ b/src/raft_log.c @@ -118,12 +118,12 @@ raft_entry_t* log_get_from_idx(log_t* me_, int idx, int *n_etys) i = (me->front + idx - me->base) % me->size; - assert(i <= me->back); + int logs_till_end_of_log; - int logs_till_end_of_log = me->back - i; - - /* idx - me->front - me->base; */ - /* i = */ + if (i < me->back) + logs_till_end_of_log = me->back - i; + else + logs_till_end_of_log = me->size - i; *n_etys = logs_till_end_of_log; return &me->entries[i];