From ef4d419989bcfe39f7ea7e50d4945c0ae24f2e85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sun, 26 Apr 2020 00:19:13 -0300 Subject: Fix element queries at page borders --- point.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/point.c b/point.c index 27d62be..aef23ef 100644 --- a/point.c +++ b/point.c @@ -15,11 +15,15 @@ uint16_t index_to_offset(struct point *point) { } uint8_t element(struct point *point) { - return point->page->elements[index_to_offset(point)]; + if (point->index == point->page->element_count) { + return point->page->next->elements[0]; + } else { + return point->page->elements[index_to_offset(point)]; + } } bool at_eof(struct point *point) { - return point->index == point->page->element_count; + return point->index == point->page->element_count && !point->page->next; } void move_point_forward(struct point *point) { -- cgit v1.2.3