summaryrefslogtreecommitdiff
path: root/usr.bin/rcs/diff3.c
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@cvs.openbsd.org>2008-03-02 19:40:59 +0000
committerTobias Stoeckmann <tobias@cvs.openbsd.org>2008-03-02 19:40:59 +0000
commit2abb924d615ef1822c89730007ec3b1610586e8d (patch)
treec7ffd6e4984e94c5714497d79583e52f34d9ea19 /usr.bin/rcs/diff3.c
parent5dc691f4170a4d2b1616c08d3a04937e1d881d10 (diff)
Make sure that temporary file has been successfully opened.
ok joris
Diffstat (limited to 'usr.bin/rcs/diff3.c')
-rw-r--r--usr.bin/rcs/diff3.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/usr.bin/rcs/diff3.c b/usr.bin/rcs/diff3.c
index 0672094cd2f..a9b5300d083 100644
--- a/usr.bin/rcs/diff3.c
+++ b/usr.bin/rcs/diff3.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff3.c,v 1.25 2007/12/23 01:15:12 tedu Exp $ */
+/* $OpenBSD: diff3.c,v 1.26 2008/03/02 19:40:58 tobias Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
@@ -72,7 +72,7 @@ static const char copyright[] =
#ifndef lint
static const char rcsid[] =
- "$OpenBSD: diff3.c,v 1.25 2007/12/23 01:15:12 tedu Exp $";
+ "$OpenBSD: diff3.c,v 1.26 2008/03/02 19:40:58 tobias Exp $";
#endif /* not lint */
#include <ctype.h>
@@ -144,7 +144,7 @@ static int edit(struct diff *, int, int);
static char *getchange(FILE *);
static char *getline(FILE *, size_t *);
static int number(char **);
-static size_t readin(char *, struct diff **);
+static ssize_t readin(char *, struct diff **);
static int skip(int, int, char *);
static int edscript(int);
static int merge(size_t, size_t);
@@ -408,7 +408,7 @@ out:
static int
diff3_internal(int argc, char **argv, const char *fmark, const char *rmark)
{
- size_t m, n;
+ ssize_t m, n;
int i;
if (argc < 5)
@@ -425,8 +425,14 @@ diff3_internal(int argc, char **argv, const char *fmark, const char *rmark)
}
increase();
- m = readin(argv[0], &d13);
- n = readin(argv[1], &d23);
+ if ((m = readin(argv[0], &d13)) < 0) {
+ warn("%s", argv[0]);
+ return (-1);
+ }
+ if ((n = readin(argv[1], &d23)) < 0) {
+ warn("%s", argv[1]);
+ return (-1);
+ }
for (i = 0; i <= 2; i++)
if ((fp[i] = fopen(argv[i + 2], "r")) == NULL) {
@@ -550,7 +556,7 @@ ed_patch_lines(struct rcs_lines *dlines, struct rcs_lines *plines)
* since the vector is processed in one sequential pass.
* The vector could be optimized out of existence)
*/
-static size_t
+static ssize_t
readin(char *name, struct diff **dd)
{
int a, b, c, d;
@@ -558,6 +564,8 @@ readin(char *name, struct diff **dd)
size_t i;
fp[0] = fopen(name, "r");
+ if (fp[0] == NULL)
+ return (-1);
for (i = 0; (p = getchange(fp[0])); i++) {
if (i >= szchanges - 1)
increase();