From 60494aff6d1661f448317cb8a4b3945b19b9b4c2 Mon Sep 17 00:00:00 2001 From: Petr Tesarik Date: Thu, 17 May 2018 21:32:00 +0200 Subject: [PATCH] Adjust hed_cursor_chunk_len() for max-sized blocks If the cursor is at the beginning of a maximum-sized block, hed_cursor_chunk_len() returns 0. Compare against the maximum block offset instead, but also add a check for empty blocks so that hed_cursor_chunk_len() still return zero in that case. Signed-off-by: Petr Tesarik --- libhed/file.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libhed/file.h b/libhed/file.h index 23a8f83..030ac49 100644 --- a/libhed/file.h +++ b/libhed/file.h @@ -220,8 +220,10 @@ hed_cursor_span(const hed_cursor_t *curs) static inline size_t hed_cursor_chunk_len(const hed_cursor_t *curs, size_t maxlen) { - hed_uoff_t ret = hed_cursor_span(curs); - return ret < maxlen ? (size_t)ret : maxlen; + hed_uoff_t ret = hed_cursor_span(curs) - 1; + return !hed_block_is_empty(curs->block) + ? ret < maxlen ? (size_t)ret + 1 : maxlen + : 0; } /* File object */ -- 2.11.4.GIT