]> git.mdlowis.com Git - projs/tide.git/commitdiff
Fixed some bad memory accesses found with valgrind
authorMichael D. Lowis <mike.lowis@gentex.com>
Wed, 31 May 2017 13:51:59 +0000 (09:51 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Wed, 31 May 2017 13:51:59 +0000 (09:51 -0400)
lib/view.c
tide.c

index 727aacedf95b740de82e70e54540ea51703ec171..4872f696351f338ee0522f2b0969669cf67373c1 100644 (file)
@@ -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 4441a24fcc3c2909dd8b4311eda345a21b2516b0..061f16cdeba0ecae6aa6394377af762c03f95ac5 100644 (file)
--- 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");