From ab248451a5cd954b1ec2813259ad51813db7e729 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 31 May 2017 09:51:59 -0400 Subject: [PATCH] Fixed some bad memory accesses found with valgrind --- lib/view.c | 3 +++ tide.c | 1 + 2 files changed, 4 insertions(+) diff --git a/lib/view.c b/lib/view.c index 727aace..4872f69 100644 --- a/lib/view.c +++ b/lib/view.c @@ -178,6 +178,8 @@ void view_init(View* view, char* file, void (*errfn)(char*)) { for (size_t i = 0; i < view->nrows; i++) free(view->rows[i]); free(view->rows); + view->nrows = 0; + view->rows = NULL; } buf_init(&(view->buffer), errfn); view->selection = (Sel){ 0 }; @@ -249,6 +251,7 @@ static void find_cursor(View* view, size_t* csrx, size_t* csry) { } void view_update(View* view, size_t* csrx, size_t* csry) { + if (!view->nrows) return; size_t csr = view->selection.end; /* scroll the view and reflow the screen lines */ reflow(view); diff --git a/tide.c b/tide.c index 4441a24..061f16c 100644 --- a/tide.c +++ b/tide.c @@ -149,6 +149,7 @@ static void quit(void) { } static bool changed_externally(Buf* buf) { + if (!buf->path) return false; bool modified = (buf->modtime != modtime(buf->path)); if (modified) ondiagmsg("File modified externally: {SaveAs } Overwrite Reload"); -- 2.52.0