On Mon, 25 Feb 2019 12:39:41 +0100, Ingo Schwarze wrote:
One question inline.
- todd
> Index: line.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/less/line.c,v
> retrieving revision 1.23
> diff -u -p -r1.23 line.c
> --- line.c 24 Feb 2019 04:54:36 -0000 1.23
> +++ line.c 25 Feb 2019 11:25:39 -0000
> @@ -230,7 +230,7 @@ pshift(int shift)
> */
> while (shifted <= shift && from < curr) {
> c = linebuf[from];
> - if (ctldisp == OPT_ONPLUS && IS_CSI_START(c)) {
> + if (ctldisp == OPT_ONPLUS && c == ESC) {
> /* Keep cumulative effect. */
> linebuf[to] = c;
> attr[to++] = attr[from++];
> @@ -469,11 +469,10 @@ in_ansi_esc_seq(void)
> * Search backwards for either an ESC (which means we ARE in a seq);
> * or an end char (which means we're NOT in a seq).
> */
> - for (p = &linebuf[curr]; p > linebuf; ) {
> - LWCHAR ch = step_char(&p, -1, linebuf);
> - if (IS_CSI_START(ch))
> + for (p = linebuf + curr - 1; p >= linebuf; p--) {
Since curr can be 0, can this lead to be a single byte underflow?
> + if (*p == ESC)
> return (1);
> - if (!is_ansi_middle(ch))
> + if (!is_ansi_middle(*p))
> return (0);
> }
> return (0);
> @@ -533,17 +532,14 @@ store_char(LWCHAR ch, char a, char *rep,
> if (ctldisp == OPT_ONPLUS && in_ansi_esc_seq()) {
> if (!is_ansi_end(ch) && !is_ansi_middle(ch)) {
> /* Remove whole unrecognized sequence. */
> - char *p = &linebuf[curr];
> - LWCHAR bch;
> do {
> - bch = step_char(&p, -1, linebuf);
> - } while (p > linebuf && !IS_CSI_START(bch));
> - curr = p - linebuf;
> + curr--;
> + } while (curr > 0 && linebuf[curr] != ESC);
> return (0);
> }
> a = AT_ANSI; /* Will force re-AT_'ing around it. */
> w = 0;
> - } else if (ctldisp == OPT_ONPLUS && IS_CSI_START(ch)) {
> + } else if (ctldisp == OPT_ONPLUS && ch == ESC) {
> a = AT_ANSI; /* Will force re-AT_'ing around it. */
> w = 0;
> } else {
> @@ -851,7 +847,7 @@ do_append(LWCHAR ch, char *rep, off_t po
> } else if ((!utf_mode || is_ascii_char(ch)) && control_char((char)ch))
> {
> do_control_char:
> if (ctldisp == OPT_ON ||
> - (ctldisp == OPT_ONPLUS && IS_CSI_START(ch))) {
> + (ctldisp == OPT_ONPLUS && ch == ESC)) {
> /*
> * Output as a normal character.
> */