From: Michael D. Lowis Date: Wed, 31 May 2017 13:51:59 +0000 (-0400) Subject: Fixed some bad memory accesses found with valgrind X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=ab248451a5cd954b1ec2813259ad51813db7e729;p=projs%2Ftide.git Fixed some bad memory accesses found with valgrind --- 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");