From 3d61efea7d46a37bcfe13d498f77a3306a43c4bc Mon Sep 17 00:00:00 2001 From: tg Date: Mon, 6 Nov 2006 19:57:19 +0000 Subject: [PATCH] =?UTF-8?q?fix=20backward=20deletion=20off-by-one=20in=20n?= =?UTF-8?q?on-border=20case=20take=20#if=200'd=20back=20debugging=20code?= =?UTF-8?q?=20for=20a=20while,=20until=20the=20next=20release=20comes=20ou?= =?UTF-8?q?t=E2=80=A6=20you=20never=20know=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- edit.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/edit.c b/edit.c index 322018d..a2064a6 100644 --- a/edit.c +++ b/edit.c @@ -5,7 +5,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.56 2006/11/05 21:11:17 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.57 2006/11/06 19:57:19 tg Exp $"); /* tty driver characters we are interested in */ typedef struct { @@ -56,6 +56,28 @@ static int x_file_glob(int, const char *, int, char ***); static int x_command_glob(int, const char *, int, char ***); static int x_locate_word(const char *, int, int, int *, int *); +#if 0 +static void D(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +static void +D(const char *fmt, ...) +{ + static FILE *_Dfp = NULL; + va_list ap; + + if (_Dfp == NULL) { + if ((_Dfp = fopen("/tmp/mksh.dbg", "ab+")) == NULL) + abort(); + fprintf(_Dfp, "\n\nOpening from %ld\n", (long)getpid()); + } + va_start(ap, fmt); + vfprintf(_Dfp, fmt, ap); + fflush(_Dfp); +} +#else +#define D(x) /* nothing */ +#endif + /* +++ generic editing functions +++ */ /* Called from main */ @@ -1705,11 +1727,9 @@ x_del_back(int c __attribute__((unused))) x_e_putc2(7); return (KSTD); } - while (i++ < x_arg) { + do { x_goto(xcp - 1); - if (xcp == xbuf) - break; - } + } while ((++i < x_arg) && (xcp != xbuf)); x_delete(i, false); return KSTD; }