From 1b9b2626eb1153042b2d1307f2ce2b9acb4c56a2 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Mon, 10 Feb 2020 23:43:28 -0800 Subject: [PATCH] some asserts --- ke/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ke/main.c b/ke/main.c index d8dbf9e..0e2b322 100644 --- a/ke/main.c +++ b/ke/main.c @@ -5,6 +5,7 @@ * https://viewsourcecode.org/snaptoken/kilo/ */ #include +#include #include #include #include @@ -95,7 +96,7 @@ ab_append(struct abuf *buf, const char *s, int len) char *nc = realloc(buf->b, buf->len + len); if (nc == NULL) { - return; + abort(); } memcpy(&nc[buf->len], s, len); @@ -229,6 +230,7 @@ insert_row(int at, char *s, size_t len) } editor.row = realloc(editor.row, sizeof(erow) * (editor.nrows + 1)); + assert(editor.row != NULL); if (at < editor.nrows) { memmove(&editor.row[at+1], &editor.row[at], @@ -277,6 +279,7 @@ void row_append_row(erow *row, char *s, int len) { row->line = realloc(row->line, row->size + len + 1); + assert(row->line != NULL); memcpy(&row->line[row->size], s, len); row->size += len; row->line[row->size] = '\0'; @@ -296,6 +299,7 @@ row_insert_ch(erow *row, int at, int16_t c) } row->line = realloc(row->line, row->size+2); + assert(row->line != NULL); memmove(&row->line[at+1], &row->line[at], row->size - at + 1); row->size++; row->line[at] = c; @@ -606,6 +610,7 @@ editor_prompt(char *prompt, void (*cb)(char *, int16_t)) if (buflen == bufsz - 1) { bufsz *= 2; buf = realloc(buf, bufsz); + assert(buf != NULL); } buf[buflen++] = c; @@ -977,6 +982,8 @@ setup_terminal() void draw_rows(struct abuf *ab) { + assert(editor.cols >= 0); + char buf[editor.cols]; int buflen, filerow, padding; int y;