aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Best <gbe@unobtanium.de>2014-09-16 13:24:37 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-09-16 20:11:57 +0200
commit2e61b4456dd3f40097cf6157d7ca53334f802637 (patch)
tree4217e96d7bdce0d6c92a44c5488320cde38b4540
parent03efb93095237310273cbe31674cdf115be53544 (diff)
downloadvis-2e61b4456dd3f40097cf6157d7ca53334f802637.tar.gz
vis-2e61b4456dd3f40097cf6157d7ca53334f802637.tar.xz
Fix editing of files with length 0
Signed-off-by: Gregor Best <gbe@unobtanium.de>
-rw-r--r--text.c8
1 files 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)