From 1939bdea53948f22fe3afa62d5bc731400c6ee0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Mon, 6 Apr 2020 00:08:10 -0300 Subject: Fix gap_end off by one --- page.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'page.c') diff --git a/page.c b/page.c index b026f6a..adc5797 100644 --- a/page.c +++ b/page.c @@ -15,7 +15,7 @@ struct page { struct page *new_page() { struct page *result = malloc(sizeof(struct page)); result->gap_start = result->buffer; - result->gap_end = result->buffer + PAGE_SIZE - 1; + result->gap_end = result->buffer + PAGE_SIZE; result->next = 0; result->prev = 0; return result; @@ -23,7 +23,7 @@ struct page *new_page() { static inline void set_half_page_gap(struct page *page) { page->gap_start = page->buffer + PAGE_SIZE / 2; - page->gap_end = page->buffer + PAGE_SIZE - 1; + page->gap_end = page->buffer + PAGE_SIZE; } void split_page(struct page *first_half) { @@ -55,14 +55,14 @@ void delete_page(struct page *page) { void move_gap(struct page *page, int target) { while(target) { if (target > 0) { - page->gap_end++; *(page->gap_start) = *(page->gap_end); page->gap_start++; + page->gap_end++; target--; } else { + page->gap_end--; page->gap_start--; *(page->gap_end) = *(page->gap_start); - page->gap_end--; target++; } } -- cgit v1.2.3