From f8d7dffddc577aa1c61c63793ec220a89c4ed32a Mon Sep 17 00:00:00 2001 From: "David C. Rankin" Date: Tue, 20 Oct 2020 23:32:31 -0500 Subject: [PATCH 1/2] abAppend() change 'new' to 'app' to remove conflict with C++ keyword --- kilo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kilo.c b/kilo.c index ba88a97..ed73cdc 100644 --- a/kilo.c +++ b/kilo.c @@ -709,11 +709,11 @@ struct abuf { #define ABUF_INIT {NULL, 0} void abAppend(struct abuf *ab, const char *s, int len) { - char *new = realloc(ab->b, ab->len + len); + char *app = realloc(ab->b, ab->len + len); - if (new == NULL) return; - memcpy(&new[ab->len], s, len); - ab->b = new; + if (app == NULL) return; + memcpy(&app[ab->len], s, len); + ab->b = app; ab->len += len; } From 274df9064796bbb2106374686f12c09ce416ea84 Mon Sep 17 00:00:00 2001 From: "David C. Rankin" Date: Wed, 21 Oct 2020 13:23:54 -0500 Subject: [PATCH 2/2] editorOpen() replace loop to trim line-endings and obtain linelen with a single call to strcspn() --- kilo.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kilo.c b/kilo.c index ed73cdc..c97bde1 100644 --- a/kilo.c +++ b/kilo.c @@ -586,9 +586,7 @@ void editorOpen(char *filename) { size_t linecap = 0; ssize_t linelen; while ((linelen = getline(&line, &linecap, fp)) != -1) { - while (linelen > 0 && (line[linelen - 1] == '\n' || - line[linelen - 1] == '\r')) - linelen--; + line[(linelen = strcspn (line, "\r\n"))] = 0; editorInsertRow(E.numrows, line, linelen); } free(line);