From 0558044ac79c1d612d58562e70628ca1d0fed0c6 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 3 Mar 2017 15:30:25 -0500 Subject: [PATCH] Fixed crash when saving an empty file --- TODO.md | 2 -- lib/buf.c | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index f88d475..29419df 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,6 @@ Up Next: -* save of an empty file crashes * implement 9term-like scrollbar * tab inserts dont coalesce like one would expect * check for file changes on save @@ -35,4 +34,3 @@ The Future: * Win-like terminal emulator * File browser * Acme-like window manager - diff --git a/lib/buf.c b/lib/buf.c index 7f183ee..22e1281 100644 --- a/lib/buf.c +++ b/lib/buf.c @@ -233,6 +233,7 @@ unsigned buf_load(Buf* buf, char* path) { } void buf_save(Buf* buf) { + if (0 == buf_end(buf)) return; size_t wrlen = 0; if (!buf->path) return; FMap file = mmap_readwrite(buf->path, buf_end(buf) * UTF_MAX); -- 2.49.0