summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2006-08-08 10:22:02 +0000
committerMarc Espie <espie@cvs.openbsd.org>2006-08-08 10:22:02 +0000
commite9cedf91efb6c7f7ed556762273a89aae838e130 (patch)
treee7a0cd4e7544994a5ede1fccdc6a3652751ded81
parenta1c83407c9863e0cbc243064f5c127527d9024bd (diff)
let ed_patch_lines work with a c command that encompasses the last line
of the file. The TAILQ structures specifically contain an extra `first line' to avoid this kind of issue, but no extra last line. Instead of walking beyond the end of the structure, and wondering at the null pointer, keep a pointer before the deleted block, as this one is guaranteed to exist. Fix Matthieu's testcase. okay joris@, xsa@
-rw-r--r--usr.bin/rcs/diff3.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/usr.bin/rcs/diff3.c b/usr.bin/rcs/diff3.c
index 4692c6a1a76..6a6f5f3866c 100644
--- a/usr.bin/rcs/diff3.c
+++ b/usr.bin/rcs/diff3.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff3.c,v 1.12 2006/08/07 20:55:28 ray Exp $ */
+/* $OpenBSD: diff3.c,v 1.13 2006/08/08 10:22:01 espie 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.12 2006/08/07 20:55:28 ray Exp $";
+ "$OpenBSD: diff3.c,v 1.13 2006/08/08 10:22:01 espie Exp $";
#endif /* not lint */
#include "includes.h"
@@ -414,7 +414,7 @@ int
ed_patch_lines(struct rcs_lines *dlines, struct rcs_lines *plines)
{
char op, *ep;
- struct rcs_line *sort, *lp, *dlp, *ndlp;
+ struct rcs_line *sort, *lp, *dlp, *ndlp, *insert_after;
int start, end, i, lineno;
dlp = TAILQ_FIRST(&(dlines->l_lines));
@@ -465,12 +465,13 @@ ed_patch_lines(struct rcs_lines *dlines, struct rcs_lines *plines)
if (op == 'c') {
+ insert_after = TAILQ_PREV(dlp, rcs_tqh, l_list);
for (i = 0; i <= (end - start); i++) {
ndlp = TAILQ_NEXT(dlp, l_list);
TAILQ_REMOVE(&(dlines->l_lines), dlp, l_list);
dlp = ndlp;
}
- dlp = TAILQ_PREV(dlp, rcs_tqh, l_list);
+ dlp = insert_after;
}
if (op == 'a' || op == 'c') {