about summary refs log tree commit diff
path: root/main.c
diff options
context:
space:
mode:
authorsternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2020-08-25 10:49:51 +0200
committersternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2020-08-25 10:55:01 +0200
commit09809f4b19e25c6f479bb43fd1a50b407c07d815 (patch)
tree5e1ebd58ac8eb458a8ac4a4b084a0d2fd88bb72d /main.c
parentf71df190128add96a89368be5c70211d6f864ee6 (diff)
feat(main): add asserts to catch bugs in routing
These assert runtime assumptions
Diffstat (limited to 'main.c')
-rw-r--r--main.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/main.c b/main.c
index de71713..8571bdc 100644
--- a/main.c
+++ b/main.c
@@ -74,6 +74,7 @@
  *
  */
 #define _POSIX_C_SOURCE 200809L
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <dirent.h>
@@ -189,6 +190,9 @@ int main(void) {
         }
     }
 
+    // confirm index is allocated if we are serving a feed
+    assert(is_feed == FEED_TYPE_NONE || page_type == PAGE_TYPE_INDEX);
+
     // construct index for feeds and index page
     if(page_type == PAGE_TYPE_INDEX) {
         count = make_index(BLOG_DIR, script_name, 0, &entries);
@@ -202,6 +206,8 @@ int main(void) {
         }
     }
 
+    // confirm status and page_type match
+    assert(status == 200 || page_type == PAGE_TYPE_ERROR);
     // render response
     if(page_type == PAGE_TYPE_ERROR) {
         send_standard_headers(status, "text/html");
@@ -215,6 +221,9 @@ int main(void) {
 
         template_header();
 
+        // confirm that PAGE_TYPE_ENTRY → count == 1
+        assert(page_type != PAGE_TYPE_ENTRY || count == 1);
+
         for(int i = 0; i < count; i++) {
             if(entries[i].text != NULL || entry_get_text(&entries[i]) != -1) {
                 if(page_type == PAGE_TYPE_INDEX) {