summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-26 22:24:46 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-26 22:24:46 -0300
commit5427bf8939f0ed254db9db32a6d96af98e641f59 (patch)
treedf4d06894c9aba85d4c7805470ea1bee9edd23f4
parentef4d419989bcfe39f7ea7e50d4945c0ae24f2e85 (diff)
downloadjet-5427bf8939f0ed254db9db32a6d96af98e641f59.tar.gz
jet-5427bf8939f0ed254db9db32a6d96af98e641f59.zip
Replace out of bound checks with asserts
-rw-r--r--page.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/page.c b/page.c
index 864623e..dd3d29a 100644
--- a/page.c
+++ b/page.c
@@ -1,6 +1,7 @@
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
+#include <assert.h>
#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
@@ -65,32 +66,28 @@ void free_page(struct page *page) {
}
void move_gap_forward(struct page *page) {
- if (page->gap_end < PAGE_SIZE) {
- page->elements[page->gap_start] = page->elements[page->gap_end];
- page->gap_start++;
- page->gap_end++;
- }
+ assert(page->gap_end < PAGE_SIZE);
+ page->elements[page->gap_start] = page->elements[page->gap_end];
+ page->gap_start++;
+ page->gap_end++;
}
void move_gap_backward(struct page *page) {
- if (page->gap_start > 0) {
- page->gap_end--;
- page->gap_start--;
- page->elements[page->gap_end] = page->elements[page->gap_start];
- }
+ assert(page->gap_start > 0);
+ page->gap_end--;
+ page->gap_start--;
+ page->elements[page->gap_end] = page->elements[page->gap_start];
}
void insert_at_gap(struct page *page, uint8_t c) {
- if (page->element_count < PAGE_SIZE) {
- page->elements[page->gap_start] = c;
- page->gap_start++;
- page->element_count++;
- }
+ assert(page->element_count < PAGE_SIZE);
+ page->elements[page->gap_start] = c;
+ page->gap_start++;
+ page->element_count++;
}
void delete_at_gap(struct page *page) {
- if (page->gap_start > 0) {
- page->gap_start--;
- page->element_count--;
- }
+ assert(page->gap_start > 0);
+ page->gap_start--;
+ page->element_count--;
}