summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/patch/inp.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/usr.bin/patch/inp.c b/usr.bin/patch/inp.c
index 6657d198390..eed1aefad68 100644
--- a/usr.bin/patch/inp.c
+++ b/usr.bin/patch/inp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: inp.c,v 1.35 2009/10/27 23:59:41 deraadt Exp $ */
+/* $OpenBSD: inp.c,v 1.36 2012/04/10 14:46:34 ajacoutot Exp $ */
/*
* patch - a program to apply diffs to original files
@@ -243,12 +243,16 @@ plan_a(const char *filename)
if ((ifd = open(filename, O_RDONLY)) < 0)
pfatal("can't open file %s", filename);
- i_womp = mmap(NULL, i_size, PROT_READ, MAP_PRIVATE, ifd, 0);
- if (i_womp == MAP_FAILED) {
- perror("mmap failed");
+ if (i_size) {
+ i_womp = mmap(NULL, i_size, PROT_READ, MAP_PRIVATE, ifd, 0);
+ if (i_womp == MAP_FAILED) {
+ perror("mmap failed");
+ i_womp = NULL;
+ close(ifd);
+ return false;
+ }
+ } else {
i_womp = NULL;
- close(ifd);
- return false;
}
close(ifd);