From bf94b7e2ec06a942bcb278354bb9b213a87475be Mon Sep 17 00:00:00 2001 From: tg Date: Wed, 14 Aug 2013 20:26:19 +0000 Subject: [PATCH] fun: when writing this code I feared an off-by-one; Steffen Daode Nurpmeso stumbled upon it and gave very detailed instructions on how to reproduce it (thanks!); fix that also only call x_bs0 if xcp < xep because *xep is undefined --- check.t | 6 +++--- edit.c | 8 ++++---- sh.h | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/check.t b/check.t index bc2ec3a..8df826f 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.628 2013/08/11 14:57:07 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.629 2013/08/14 20:26:15 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -31,7 +31,7 @@ # http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD expected-stdout: - @(#)MIRBSD KSH R48 2013/08/11 + @(#)MIRBSD KSH R48 2013/08/14 description: Check version of shell. stdin: @@ -40,7 +40,7 @@ name: KSH_VERSION category: shell:legacy-no --- expected-stdout: - @(#)LEGACY KSH R48 2013/08/11 + @(#)LEGACY KSH R48 2013/08/14 description: Check version of legacy shell. stdin: diff --git a/edit.c b/edit.c index c464f31..675e7ed 100644 --- a/edit.c +++ b/edit.c @@ -28,7 +28,7 @@ #ifndef MKSH_NO_CMDLINE_EDITING -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.269 2013/08/10 13:44:29 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.270 2013/08/14 20:26:17 tg Exp $"); /* * in later versions we might use libtermcap for this, but since external @@ -2828,15 +2828,15 @@ x_adjust(void) goto x_adjust_out; } - /* fix up xbp to character begin first */ - xbp = x_bs0(xcp, xbuf); + /* fix up xbp to just past a character end first */ + xbp = xcp >= xep ? xep : x_bs0(xcp, xbuf); /* walk backwards */ while (xbp > xbuf && col_left > 0) { xbp = x_bs0(xbp - 1, xbuf); col_left -= (n = x_size2(xbp, NULL)); } /* check if we hit the prompt */ - if (xbp == xbuf && xcp != xbuf && col_left > 0 && col_left < pwidth) { + if (xbp == xbuf && xcp != xbuf && col_left >= 0 && col_left < pwidth) { /* so we did; force scrolling occurs */ xbp += utf_ptradj(xbp); } diff --git a/sh.h b/sh.h index 0b89120..5a95190 100644 --- a/sh.h +++ b/sh.h @@ -164,9 +164,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.666 2013/08/11 14:57:10 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.667 2013/08/14 20:26:19 tg Exp $"); #endif -#define MKSH_VERSION "R48 2013/08/11" +#define MKSH_VERSION "R48 2013/08/14" /* arithmetic types: C implementation */ #if !HAVE_CAN_INTTYPES