From 7db6ffa2267a210cd7bbffa0c55f68656e396234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Fri, 24 Apr 2020 15:35:29 -0300 Subject: Fix deleting first page corrupting page pointer --- point.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'point.c') diff --git a/point.c b/point.c index 7977a4e..27d62be 100644 --- a/point.c +++ b/point.c @@ -35,8 +35,8 @@ void move_point_backward(struct point *point) { if (point->index > 1) { point->index--; } else if (point->page->prev) { - point->index = point->page->prev->element_count; point->page = point->page->prev; + point->index = point->page->element_count; } else { point->index = 0; } @@ -65,15 +65,14 @@ void insert_at_point(struct point *point, uint8_t c) { } void delete_at_point(struct point *point) { - if (point->page->element_count == 1) { + if (point->page->element_count == 1 && point->index == 1) { if (point->page->prev) { - point->page = point->page->prev; - point->index = point->page->element_count; + move_point_backward(point); free_page(point->page->next); } else if (point->page->next) { - point->page = point->page->next; + copy_page(point->page, point->page->next); + free_page(point->page->next); point->index = 0; - free_page(point->page->prev); } else { align_gap(point); delete_at_gap(point->page); -- cgit v1.2.3