[PATCH 1/2] Fix editing of files with length 0

From: Gregor Best <gbe_AT_unobtanium.de>
Date: Tue, 16 Sep 2014 13:24:37 +0200

Signed-off-by: Gregor Best <gbe_AT_unobtanium.de>
---
 text.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/text.c b/text.c
index 2bdfe75..9aa8b2c 100644
--- a/text.c
+++ b/text.c
_AT_@ -663,9 +663,15 @@ 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 = NULL;
+		} else {
+			txt->buf.data = mmap(NULL, txt->info.st_size, PROT_READ, MAP_SHARED, txt->fd, 0);
+			if (txt->buf.data == MAP_FAILED) {
+				perror("mmap");
+				goto out;
+			}
+		}
 
 		Piece *p = piece_alloc(txt);
 		if (!p)
-- 
2.1.0
--gj572EiMnwbLXET9
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="0002-Fix-compilation-on-OpenBSD.patch"
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Tue Sep 16 2014 - 14:48:03 CEST