summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-06 00:08:10 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-06 00:08:10 -0300
commit1939bdea53948f22fe3afa62d5bc731400c6ee0a (patch)
tree823def9c2bf5cbe118055eb4e2a7f8ee7f1b9d7b
parente7117322149fdc0196acb49c2ae0ff32e2c299c0 (diff)
downloadjet-1939bdea53948f22fe3afa62d5bc731400c6ee0a.tar.gz
jet-1939bdea53948f22fe3afa62d5bc731400c6ee0a.zip
Fix gap_end off by one
-rw-r--r--page.c8
1 files changed, 4 insertions, 4 deletions
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++;
}
}