summaryrefslogtreecommitdiff
path: root/point.c
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-24 15:35:29 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-24 15:35:29 -0300
commit7db6ffa2267a210cd7bbffa0c55f68656e396234 (patch)
tree8f9b42180b852e4046f7dad4bb661de39c4f6c28 /point.c
parenta1a381926626aa44e264cd24dbf35e26f3d52330 (diff)
downloadjet-7db6ffa2267a210cd7bbffa0c55f68656e396234.tar.gz
jet-7db6ffa2267a210cd7bbffa0c55f68656e396234.zip
Fix deleting first page corrupting page pointer
Diffstat (limited to 'point.c')
-rw-r--r--point.c11
1 files changed, 5 insertions, 6 deletions
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);