From 2e61b4456dd3f40097cf6157d7ca53334f802637 Mon Sep 17 00:00:00 2001 From: Gregor Best Date: Tue, 16 Sep 2014 13:24:37 +0200 Subject: Fix editing of files with length 0 Signed-off-by: Gregor Best --- text.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/text.c b/text.c index 2bdfe75..c917781 100644 --- a/text.c +++ b/text.c @@ -663,9 +663,11 @@ Text *text_load(const char *filename) { goto out; // XXX: use lseek(fd, 0, SEEK_END); instead? txt->buf.size = txt->info.st_size; - txt->buf.data = mmap(NULL, txt->info.st_size, PROT_READ, MAP_SHARED, txt->fd, 0); - if (txt->buf.data == MAP_FAILED) - goto out; + if (txt->buf.size != 0) { + txt->buf.data = mmap(NULL, txt->info.st_size, PROT_READ, MAP_SHARED, txt->fd, 0); + if (txt->buf.data == MAP_FAILED) + goto out; + } Piece *p = piece_alloc(txt); if (!p) -- cgit v1.2.3