CVS commit: src/external/bsd/nvi/dist/vi
Module Name:src Committed By: rin Date: Tue Jul 7 10:58:43 UTC 2020 Modified Files: src/external/bsd/nvi/dist/vi: v_txt.c Log Message: PR bin/55468 Fix crash due to out-of-bounds access with Ctrl-W. PR is only for nottywerase, but also fix ttywerase case, taken from OpenBSD via nvi2: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/vi/vi/v_txt.c#rev1.23 https://github.com/lichray/nvi2/commit/5d5365d3585f45651f9b4a366391798a91393337 Also, comment there is no worry for altwerase specific code, which seems suspicious at a glance. Reported by Azuma OKAMOTO. Thanks for detailed explanation how to reproduce the problem! To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/external/bsd/nvi/dist/vi/v_txt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/nvi/dist/vi/v_txt.c diff -u src/external/bsd/nvi/dist/vi/v_txt.c:1.6 src/external/bsd/nvi/dist/vi/v_txt.c:1.7 --- src/external/bsd/nvi/dist/vi/v_txt.c:1.6 Tue Aug 7 08:05:47 2018 +++ src/external/bsd/nvi/dist/vi/v_txt.c Tue Jul 7 10:58:43 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: v_txt.c,v 1.6 2018/08/07 08:05:47 rin Exp $ */ +/* $NetBSD: v_txt.c,v 1.7 2020/07/07 10:58:43 rin Exp $ */ /*- * Copyright (c) 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -16,7 +16,7 @@ static const char sccsid[] = "Id: v_txt.c,v 10.108 2003/07/18 21:27:42 skimo Exp (Berkeley) Date: 2003/07/18 21:27:42 "; #endif /* not lint */ #else -__RCSID("$NetBSD: v_txt.c,v 1.6 2018/08/07 08:05:47 rin Exp $"); +__RCSID("$NetBSD: v_txt.c,v 1.7 2020/07/07 10:58:43 rin Exp $"); #endif #include @@ -1118,32 +1118,30 @@ leftmargin: tp->lb[tp->cno - 1] = ' '; */ if (LF_ISSET(TXT_TTYWERASE)) while (tp->cno > max) { +if (ISBLANK((UCHAR_T)tp->lb[tp->cno - 1])) + break; --tp->cno; ++tp->owrite; if (FL_ISSET(is_flags, IS_RUNNING)) tp->lb[tp->cno] = ' '; -if (ISBLANK((UCHAR_T)tp->lb[tp->cno - 1])) - break; } else { if (LF_ISSET(TXT_ALTWERASE)) { ---tp->cno; +--tp->cno; /* No worry for out of bounds. */ ++tp->owrite; if (FL_ISSET(is_flags, IS_RUNNING)) tp->lb[tp->cno] = ' '; -if (ISBLANK((UCHAR_T)tp->lb[tp->cno - 1])) - break; } if (tp->cno > max) tmp = inword((UCHAR_T)tp->lb[tp->cno - 1]); while (tp->cno > max) { +if (tmp != inword((UCHAR_T)tp->lb[tp->cno - 1]) +|| ISBLANK((UCHAR_T)tp->lb[tp->cno - 1])) + break; --tp->cno; ++tp->owrite; if (FL_ISSET(is_flags, IS_RUNNING)) tp->lb[tp->cno] = ' '; -if (tmp != inword((UCHAR_T)tp->lb[tp->cno - 1]) -|| ISBLANK((UCHAR_T)tp->lb[tp->cno - 1])) - break; } }
CVS commit: src/external/bsd/nvi/dist/vi
Module Name:src Committed By: rin Date: Tue Apr 10 12:44:41 UTC 2018 Modified Files: src/external/bsd/nvi/dist/vi: vs_refresh.c Log Message: PR bin/53164: Comment why we abort here. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/external/bsd/nvi/dist/vi/vs_refresh.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/nvi/dist/vi/vs_refresh.c diff -u src/external/bsd/nvi/dist/vi/vs_refresh.c:1.9 src/external/bsd/nvi/dist/vi/vs_refresh.c:1.10 --- src/external/bsd/nvi/dist/vi/vs_refresh.c:1.9 Sun Feb 4 09:15:45 2018 +++ src/external/bsd/nvi/dist/vi/vs_refresh.c Tue Apr 10 12:44:41 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: vs_refresh.c,v 1.9 2018/02/04 09:15:45 mrg Exp $ */ +/* $NetBSD: vs_refresh.c,v 1.10 2018/04/10 12:44:41 rin Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -16,7 +16,7 @@ static const char sccsid[] = "Id: vs_refresh.c,v 10.50 2001/06/25 15:19:37 skimo Exp (Berkeley) Date: 2001/06/25 15:19:37 "; #endif /* not lint */ #else -__RCSID("$NetBSD: vs_refresh.c,v 1.9 2018/02/04 09:15:45 mrg Exp $"); +__RCSID("$NetBSD: vs_refresh.c,v 1.10 2018/04/10 12:44:41 rin Exp $"); #endif #include @@ -723,7 +723,7 @@ done_cursor: #else if (vip->sc_smap == NULL) { if (F_ISSET(sp, SC_SCR_REFORMAT)) - abort(); /* XXX */ + abort(); /* XXX infinite recursion */ F_SET(sp, SC_SCR_REFORMAT); return (vs_paint(sp, flags)); }
CVS commit: src/external/bsd/nvi/dist/vi
Module Name:src Committed By: rin Date: Tue Nov 14 12:20:56 UTC 2017 Modified Files: src/external/bsd/nvi/dist/vi: vs_refresh.c Log Message: Fix cursor movement for the case of USE_WIDECHAR != "yes", where the argument of INTISWIDE() is not evaluated. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/external/bsd/nvi/dist/vi/vs_refresh.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/nvi/dist/vi/vs_refresh.c diff -u src/external/bsd/nvi/dist/vi/vs_refresh.c:1.7 src/external/bsd/nvi/dist/vi/vs_refresh.c:1.8 --- src/external/bsd/nvi/dist/vi/vs_refresh.c:1.7 Fri Nov 10 14:44:13 2017 +++ src/external/bsd/nvi/dist/vi/vs_refresh.c Tue Nov 14 12:20:55 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vs_refresh.c,v 1.7 2017/11/10 14:44:13 rin Exp $ */ +/* $NetBSD: vs_refresh.c,v 1.8 2017/11/14 12:20:55 rin Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -16,7 +16,7 @@ static const char sccsid[] = "Id: vs_refresh.c,v 10.50 2001/06/25 15:19:37 skimo Exp (Berkeley) Date: 2001/06/25 15:19:37 "; #endif /* not lint */ #else -__RCSID("$NetBSD: vs_refresh.c,v 1.7 2017/11/10 14:44:13 rin Exp $"); +__RCSID("$NetBSD: vs_refresh.c,v 1.8 2017/11/14 12:20:55 rin Exp $"); #endif #include @@ -484,7 +484,8 @@ adjust: if (!O_ISSET(sp, O_LEFTRIGHT) && * boundary, we have no hope to speed it up. Do it slowly. */ p += OCNO; - if (INTISWIDE(ch = (UCHAR_T)*p)) + ch = (UCHAR_T)*p; + if (INTISWIDE(ch)) cwtotal = SCNO; else { if (ch == '\t' || (chlen = KEY_LEN(sp, ch)) > SCNO + 1) @@ -537,7 +538,8 @@ adjust: if (!O_ISSET(sp, O_LEFTRIGHT) && * of wide characters. */ p += OCNO; - if (INTISWIDE(ch = (UCHAR_T)*p)) + ch = (UCHAR_T)*p; + if (INTISWIDE(ch)) cwtotal = SCNO; else cwtotal = SCNO + 1 - KEY_LEN(sp, ch); @@ -558,7 +560,8 @@ adjust: if (!O_ISSET(sp, O_LEFTRIGHT) && goto slow; cwtotal += KEY_COL(sp, ch); cnt--; - if (INTISWIDE(ch = (UCHAR_T)*++p) + ch = (UCHAR_T)*++p; + if (INTISWIDE(ch) && (chlen = CHAR_WIDTH(sp, ch)) > 1 && cwtotal + chlen >= SCREEN_COLS(sp)) cwtotal = SCREEN_COLS(sp);
CVS commit: src/external/bsd/nvi/dist/vi
Module Name:src Committed By: rin Date: Fri Nov 10 14:44:13 UTC 2017 Modified Files: src/external/bsd/nvi/dist/vi: vs_line.c vs_refresh.c vs_relative.c Log Message: - Fix cursor position when a multiwidth char does not fit within a line. - Put cursor on the leftmost column of a multiwidth char, instead of the rightmost one. Otherwise, some terminal emulators do not focus on the entire of the char. Logic taken from nvi-m17n by itojun. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/external/bsd/nvi/dist/vi/vs_line.c \ src/external/bsd/nvi/dist/vi/vs_relative.c cvs rdiff -u -r1.6 -r1.7 src/external/bsd/nvi/dist/vi/vs_refresh.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/nvi/dist/vi/vs_line.c diff -u src/external/bsd/nvi/dist/vi/vs_line.c:1.3 src/external/bsd/nvi/dist/vi/vs_line.c:1.4 --- src/external/bsd/nvi/dist/vi/vs_line.c:1.3 Sun Jan 26 21:43:45 2014 +++ src/external/bsd/nvi/dist/vi/vs_line.c Fri Nov 10 14:44:13 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vs_line.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */ +/* $NetBSD: vs_line.c,v 1.4 2017/11/10 14:44:13 rin Exp $ */ /*- * Copyright (c) 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -16,7 +16,7 @@ static const char sccsid[] = "Id: vs_line.c,v 10.38 2002/01/19 21:59:07 skimo Exp (Berkeley) Date: 2002/01/19 21:59:07 "; #endif /* not lint */ #else -__RCSID("$NetBSD: vs_line.c,v 1.3 2014/01/26 21:43:45 christos Exp $"); +__RCSID("$NetBSD: vs_line.c,v 1.4 2017/11/10 14:44:13 rin Exp $"); #endif #include @@ -271,38 +271,64 @@ empty: (void)gp->scr_addstr(sp, /* Do it the hard way, for leftright scrolling screens. */ if (O_ISSET(sp, O_LEFTRIGHT)) { - for (; offset_in_line < len; ++offset_in_line) { - chlen = (ch = (UCHAR_T)*p++) == L('\t') && !list_tab ? + while (offset_in_line < len) { + ch = (UCHAR_T)*p; + chlen = (ch == '\t' && !list_tab) ? TAB_OFF(scno) : KEY_COL(sp, ch); - if ((scno += chlen) >= skip_cols) -break; + + /* easy cases first. */ + if (scno + chlen < skip_cols) { +scno += chlen; +p++; +offset_in_line++; +continue; + } + + if (scno + chlen == skip_cols) { +scno += chlen; +p++; +offset_in_line++; + } + + break; } /* Set cols_per_screen to 2nd and later line length. */ cols_per_screen = sp->cols; /* Put starting info for this line in the cache. */ - if (offset_in_line >= len) { - smp->c_sboff = offset_in_line; - smp->c_scoff = 255; - } else if (scno != skip_cols) { - smp->c_sboff = offset_in_line; - smp->c_scoff = - offset_in_char = chlen - (scno - skip_cols); - --p; - } else { - smp->c_sboff = ++offset_in_line; - smp->c_scoff = 0; - } + smp->c_sboff = offset_in_line; + smp->c_scoff = offset_in_char = scno + chlen - skip_cols; } /* Do it the hard way, for historic line-folding screens. */ else { - for (; offset_in_line < len; ++offset_in_line) { - chlen = (ch = (UCHAR_T)*p++) == L('\t') && !list_tab ? + while (offset_in_line < len) { + ch = (UCHAR_T)*p; + chlen = (ch == '\t' && !list_tab) ? TAB_OFF(scno) : KEY_COL(sp, ch); - if ((scno += chlen) < cols_per_screen) + + /* Easy case first. */ + if (scno + chlen < cols_per_screen) { +scno += chlen; +p++; +offset_in_line++; continue; + } + + /* + * Since we can't generally cross the rightmost column + * by displaying multi-width char, we must check it. + * In that case, we fake the scno so that you'll see + * that the line was already filled up completely. + */ + if (!INTISWIDE(ch) || scno + chlen == cols_per_screen) { +scno += chlen; +p++; +offset_in_line++; + } else +scno = cols_per_screen; + scno -= cols_per_screen; /* Set cols_per_screen to 2nd and later line length. */ @@ -320,9 +346,10 @@ empty: (void)gp->scr_addstr(sp, if (scno != 0) { smp->c_sboff = offset_in_line; smp->c_scoff = offset_in_char = chlen - scno; - --p; + offset_in_line--; + p--; } else { - smp->c_sboff = ++offset_in_line; + smp->c_sboff = offset_in_line; smp->c_scoff = 0; } } @@ -334,10 +361,16 @@ display: * called repeatedly with a valid pointer to a cursor position. * Don't fill anything in unless it's the right line and the right * character, and the right part of the character... + * + * It is not true that every wide chars occupy at least single column. + * - It is safe to compare sp->cno and offset_in_line since they are + * both offset in unit of CHAR_T. + * - We can't simply compare offset_in_line + cols_per_screen against + * sp->cno, since cols_per_screen is screen column, not offset in + * CHAR_T. Do it slowly. */ if (yp == NULL || - smp->lno != sp->lno || sp->cno < offset_in_line || - offset_in_line + cols_per_screen < sp->cno) { +
CVS commit: src/external/bsd/nvi/dist/vi
Module Name:src Committed By: pgoyette Date: Sun Oct 22 06:26:01 UTC 2017 Modified Files: src/external/bsd/nvi/dist/vi: v_cmd.c Log Message: Remove superfluous space character. >From rjc via https://github.com/NetBSD/src/pull/1 To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/external/bsd/nvi/dist/vi/v_cmd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/nvi/dist/vi/v_cmd.c diff -u src/external/bsd/nvi/dist/vi/v_cmd.c:1.3 src/external/bsd/nvi/dist/vi/v_cmd.c:1.4 --- src/external/bsd/nvi/dist/vi/v_cmd.c:1.3 Sun Jan 26 21:43:45 2014 +++ src/external/bsd/nvi/dist/vi/v_cmd.c Sun Oct 22 06:26:01 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: v_cmd.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */ +/* $NetBSD: v_cmd.c,v 1.4 2017/10/22 06:26:01 pgoyette Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -16,7 +16,7 @@ static const char sccsid[] = "Id: v_cmd.c,v 10.9 1996/03/28 15:18:39 bostic Exp (Berkeley) Date: 1996/03/28 15:18:39 "; #endif /* not lint */ #else -__RCSID("$NetBSD: v_cmd.c,v 1.3 2014/01/26 21:43:45 christos Exp $"); +__RCSID("$NetBSD: v_cmd.c,v 1.4 2017/10/22 06:26:01 pgoyette Exp $"); #endif #include @@ -137,7 +137,7 @@ VIKEYS const vikeys [MAXVIKEY + 1] = { /* 034 ^\ */ {v_exmode, 0, "^\\", - " ^\\ switch to ex mode"}, + "^\\ switch to ex mode"}, /* 035 ^] */ {v_tagpush, V_ABS|V_KEYW|VM_RCM_SET, "^]",
CVS commit: src/external/bsd/nvi/dist/vi
Module Name:src Committed By: rin Date: Sun Jan 22 05:11:22 UTC 2017 Modified Files: src/external/bsd/nvi/dist/vi: v_paragraph.c Log Message: Respect coding style of upstream; revert r1.4 and put back parentheses. No binary changes. Pointed out by mrg. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/external/bsd/nvi/dist/vi/v_paragraph.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/nvi/dist/vi/v_paragraph.c diff -u src/external/bsd/nvi/dist/vi/v_paragraph.c:1.5 src/external/bsd/nvi/dist/vi/v_paragraph.c:1.6 --- src/external/bsd/nvi/dist/vi/v_paragraph.c:1.5 Sat Jan 21 22:22:28 2017 +++ src/external/bsd/nvi/dist/vi/v_paragraph.c Sun Jan 22 05:11:22 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: v_paragraph.c,v 1.5 2017/01/21 22:22:28 rin Exp $ */ +/* $NetBSD: v_paragraph.c,v 1.6 2017/01/22 05:11:22 rin Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -16,7 +16,7 @@ static const char sccsid[] = "Id: v_paragraph.c,v 10.10 2001/06/25 15:19:32 skimo Exp (Berkeley) Date: 2001/06/25 15:19:32 "; #endif /* not lint */ #else -__RCSID("$NetBSD: v_paragraph.c,v 1.5 2017/01/21 22:22:28 rin Exp $"); +__RCSID("$NetBSD: v_paragraph.c,v 1.6 2017/01/22 05:11:22 rin Exp $"); #endif #include @@ -94,14 +94,14 @@ v_paragraphf(SCR *sp, VICMD *vp) * hesitate, just hit them. */ if (db_last(sp, )) - return 1; + return (1); lno = vp->m_start.lno; if (ISMOTION(vp) && lno != lastlno) { if ((cno = vp->m_start.cno) == 0) F_SET(vp, VM_LMODE); else { if (nonblank(sp, lno, )) -return 1; +return (1); if (cno <= len) F_SET(vp, VM_LMODE); } @@ -114,9 +114,9 @@ v_paragraphf(SCR *sp, VICMD *vp) if (db_eget(sp, lno, , , )) { if (isempty) { vp->m_stop = vp->m_final = vp->m_start; - return 0; + return (0); } else - return 1; + return (1); } /* @@ -138,7 +138,7 @@ v_paragraphf(SCR *sp, VICMD *vp) if (++lno > lastlno) goto eof; if (db_get(sp, lno, 0, , )) - return 1; + return (1); switch (pstate) { case P_INTEXT: INTEXT_CHECK; @@ -168,7 +168,7 @@ found: if (ISMOTION(vp)) { vp->m_stop.cno = 0; vp->m_final = vp->m_stop; } - return 0; + return (0); default: abort(); } @@ -184,7 +184,7 @@ found: if (ISMOTION(vp)) { eof: lastcno = len ? len - 1 : 0; if (vp->m_start.lno == lastlno && vp->m_start.cno == lastcno) { v_eof(sp, NULL); - return 1; + return (1); } /* * !!! @@ -201,7 +201,7 @@ eof: lastcno = len ? len - 1 : 0; vp->m_stop.lno = lastlno; vp->m_stop.cno = lastcno; vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop; - return 0; + return (0); } /* @@ -243,7 +243,7 @@ v_paragraphb(SCR *sp, VICMD *vp) if (vp->m_start.cno == 0) { if (vp->m_start.lno == 1) { v_sof(sp, >m_start); -return 1; +return (1); } else --vp->m_start.lno; F_SET(vp, VM_LMODE); @@ -309,7 +309,7 @@ found: vp->m_stop.lno = lno; * adjusted the start of the range for motion commands). */ vp->m_final = vp->m_stop; - return 0; + return (0); } /* @@ -333,7 +333,7 @@ v_buildps(SCR *sp, const char *p_p, cons s_len = s_p == NULL ? 0 : strlen(s_p); if (p_len == 0 && s_len == 0) - return 0; + return (0); MALLOC_RET(sp, p, char *, p_len + s_len + 1); @@ -346,5 +346,5 @@ v_buildps(SCR *sp, const char *p_p, cons if (s_p != NULL) memmove(p + p_len, s_p, s_len + 1); vip->ps = p; - return 0; + return (0); }
CVS commit: src/external/bsd/nvi/dist/vi
Module Name:src Committed By: rin Date: Sat Jan 21 22:22:28 UTC 2017 Modified Files: src/external/bsd/nvi/dist/vi: v_paragraph.c Log Message: Fix a strange corner case in } command. When } command is executed in the last paragraph including EOF, the original vi (traditional/SVR4) moves the cursor to the *last* character in the last line. However, nvi moves it to the *first* character in the last line. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/external/bsd/nvi/dist/vi/v_paragraph.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/nvi/dist/vi/v_paragraph.c diff -u src/external/bsd/nvi/dist/vi/v_paragraph.c:1.4 src/external/bsd/nvi/dist/vi/v_paragraph.c:1.5 --- src/external/bsd/nvi/dist/vi/v_paragraph.c:1.4 Sat Jan 21 22:06:46 2017 +++ src/external/bsd/nvi/dist/vi/v_paragraph.c Sat Jan 21 22:22:28 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: v_paragraph.c,v 1.4 2017/01/21 22:06:46 rin Exp $ */ +/* $NetBSD: v_paragraph.c,v 1.5 2017/01/21 22:22:28 rin Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -16,7 +16,7 @@ static const char sccsid[] = "Id: v_paragraph.c,v 10.10 2001/06/25 15:19:32 skimo Exp (Berkeley) Date: 2001/06/25 15:19:32 "; #endif /* not lint */ #else -__RCSID("$NetBSD: v_paragraph.c,v 1.4 2017/01/21 22:06:46 rin Exp $"); +__RCSID("$NetBSD: v_paragraph.c,v 1.5 2017/01/21 22:22:28 rin Exp $"); #endif #include @@ -73,8 +73,8 @@ int v_paragraphf(SCR *sp, VICMD *vp) { enum { P_INTEXT, P_INBLANK } pstate; - size_t lastlen, len; - db_recno_t cnt, lastlno, lno; + size_t lastcno, cno, prevlen, len; + db_recno_t cnt, lastlno, prevlno, lno; int isempty; CHAR_T *p; char *lp; @@ -93,23 +93,31 @@ v_paragraphf(SCR *sp, VICMD *vp) * line itself remained. If somebody complains, don't pause, don't * hesitate, just hit them. */ - if (ISMOTION(vp)) { - if (vp->m_start.cno == 0) + if (db_last(sp, )) + return 1; + lno = vp->m_start.lno; + if (ISMOTION(vp) && lno != lastlno) { + if ((cno = vp->m_start.cno) == 0) F_SET(vp, VM_LMODE); else { - vp->m_stop = vp->m_start; - vp->m_stop.cno = 0; - if (nonblank(sp, vp->m_stop.lno, >m_stop.cno)) + if (nonblank(sp, lno, )) return 1; - if (vp->m_start.cno <= vp->m_stop.cno) + if (cno <= len) F_SET(vp, VM_LMODE); } } - /* Figure out what state we're currently in. */ - lno = vp->m_start.lno; - if (db_get(sp, lno, 0, , )) - goto eof; + /* + * Figure out what state we're currently in. It also historically + * worked on empty files, so we have to make it okay. + */ + if (db_eget(sp, lno, , , )) { + if (isempty) { + vp->m_stop = vp->m_final = vp->m_start; + return 0; + } else + return 1; + } /* * If we start in text, we want to switch states @@ -125,10 +133,12 @@ v_paragraphf(SCR *sp, VICMD *vp) } for (;;) { - lastlno = lno; - lastlen = len; - if (db_get(sp, ++lno, 0, , )) + prevlno = lno; + prevlen = len; + if (++lno > lastlno) goto eof; + if (db_get(sp, lno, 0, , )) + return 1; switch (pstate) { case P_INTEXT: INTEXT_CHECK; @@ -150,8 +160,8 @@ v_paragraphf(SCR *sp, VICMD *vp) * to the start of the new "paragraph". */ found: if (ISMOTION(vp)) { -vp->m_stop.lno = lastlno; -vp->m_stop.cno = lastlen ? lastlen - 1 : 0; +vp->m_stop.lno = prevlno; +vp->m_stop.cno = prevlen ? prevlen - 1 : 0; vp->m_final = vp->m_start; } else { vp->m_stop.lno = lno; @@ -169,20 +179,12 @@ found: if (ISMOTION(vp)) { * Adjust end of the range for motion commands; EOF is a movement * sink. The } command historically moved to the end of the last * line, not the beginning, from any position before the end of the - * last line. It also historically worked on empty files, so we - * have to make it okay. + * last line. */ -eof: if (vp->m_start.lno == lno || vp->m_start.lno == lno - 1) { - if (db_eget(sp, vp->m_start.lno, , , )) { - if (!isempty) -return 1; - vp->m_start.cno = 0; - return 0; - } - if (vp->m_start.cno == (len ? len - 1 : 0)) { - v_eof(sp, NULL); - return 1; - } +eof: lastcno = len ? len - 1 : 0; + if (vp->m_start.lno == lastlno && vp->m_start.cno == lastcno) { + v_eof(sp, NULL); + return 1; } /* * !!! @@ -196,8 +198,8 @@ eof: if (vp->m_start.lno == lno || vp->m F_CLR(vp, VM_RCM_MASK); F_SET(vp, VM_RCM_SETFNB); } - vp->m_stop.lno = lno - 1; - vp->m_stop.cno = len ? len - 1 : 0; + vp->m_stop.lno = lastlno; + vp->m_stop.cno = lastcno; vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop; return 0; }
CVS commit: src/external/bsd/nvi/dist/vi
Module Name:src Committed By: rin Date: Sat Jan 21 22:06:46 UTC 2017 Modified Files: src/external/bsd/nvi/dist/vi: v_paragraph.c Log Message: KNF; remove parentheses from return's To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/external/bsd/nvi/dist/vi/v_paragraph.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/nvi/dist/vi/v_paragraph.c diff -u src/external/bsd/nvi/dist/vi/v_paragraph.c:1.3 src/external/bsd/nvi/dist/vi/v_paragraph.c:1.4 --- src/external/bsd/nvi/dist/vi/v_paragraph.c:1.3 Sun Jan 26 21:43:45 2014 +++ src/external/bsd/nvi/dist/vi/v_paragraph.c Sat Jan 21 22:06:46 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: v_paragraph.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */ +/* $NetBSD: v_paragraph.c,v 1.4 2017/01/21 22:06:46 rin Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -16,7 +16,7 @@ static const char sccsid[] = "Id: v_paragraph.c,v 10.10 2001/06/25 15:19:32 skimo Exp (Berkeley) Date: 2001/06/25 15:19:32 "; #endif /* not lint */ #else -__RCSID("$NetBSD: v_paragraph.c,v 1.3 2014/01/26 21:43:45 christos Exp $"); +__RCSID("$NetBSD: v_paragraph.c,v 1.4 2017/01/21 22:06:46 rin Exp $"); #endif #include @@ -100,7 +100,7 @@ v_paragraphf(SCR *sp, VICMD *vp) vp->m_stop = vp->m_start; vp->m_stop.cno = 0; if (nonblank(sp, vp->m_stop.lno, >m_stop.cno)) -return (1); +return 1; if (vp->m_start.cno <= vp->m_stop.cno) F_SET(vp, VM_LMODE); } @@ -158,7 +158,7 @@ found: if (ISMOTION(vp)) { vp->m_stop.cno = 0; vp->m_final = vp->m_stop; } - return (0); + return 0; default: abort(); } @@ -175,13 +175,13 @@ found: if (ISMOTION(vp)) { eof: if (vp->m_start.lno == lno || vp->m_start.lno == lno - 1) { if (db_eget(sp, vp->m_start.lno, , , )) { if (!isempty) -return (1); +return 1; vp->m_start.cno = 0; - return (0); + return 0; } if (vp->m_start.cno == (len ? len - 1 : 0)) { v_eof(sp, NULL); - return (1); + return 1; } } /* @@ -199,7 +199,7 @@ eof: if (vp->m_start.lno == lno || vp->m vp->m_stop.lno = lno - 1; vp->m_stop.cno = len ? len - 1 : 0; vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop; - return (0); + return 0; } /* @@ -241,7 +241,7 @@ v_paragraphb(SCR *sp, VICMD *vp) if (vp->m_start.cno == 0) { if (vp->m_start.lno == 1) { v_sof(sp, >m_start); -return (1); +return 1; } else --vp->m_start.lno; F_SET(vp, VM_LMODE); @@ -307,7 +307,7 @@ found: vp->m_stop.lno = lno; * adjusted the start of the range for motion commands). */ vp->m_final = vp->m_stop; - return (0); + return 0; } /* @@ -331,7 +331,7 @@ v_buildps(SCR *sp, const char *p_p, cons s_len = s_p == NULL ? 0 : strlen(s_p); if (p_len == 0 && s_len == 0) - return (0); + return 0; MALLOC_RET(sp, p, char *, p_len + s_len + 1); @@ -344,5 +344,5 @@ v_buildps(SCR *sp, const char *p_p, cons if (s_p != NULL) memmove(p + p_len, s_p, s_len + 1); vip->ps = p; - return (0); + return 0; }
CVS commit: src/external/bsd/nvi/dist/vi
Module Name:src Committed By: christos Date: Mon Jan 6 14:21:37 UTC 2014 Modified Files: src/external/bsd/nvi/dist/vi: v_search.c Log Message: PR/48502: M. Levinson: vi(1) no longer moves the cursor when yanking text using a mark (remove dangling else) To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/external/bsd/nvi/dist/vi/v_search.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/nvi/dist/vi/v_search.c diff -u src/external/bsd/nvi/dist/vi/v_search.c:1.4 src/external/bsd/nvi/dist/vi/v_search.c:1.5 --- src/external/bsd/nvi/dist/vi/v_search.c:1.4 Wed Dec 25 12:18:39 2013 +++ src/external/bsd/nvi/dist/vi/v_search.c Mon Jan 6 09:21:37 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: v_search.c,v 1.4 2013/12/25 17:18:39 christos Exp $ */ +/* $NetBSD: v_search.c,v 1.5 2014/01/06 14:21:37 christos Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -525,7 +525,7 @@ v_correct(SCR *sp, VICMD *vp, int isdelt m = vp-m_start; vp-m_start = vp-m_stop; vp-m_stop = m; - } else + } /* * BACKWARD:
CVS commit: src/external/bsd/nvi/dist/vi
Module Name:src Committed By: christos Date: Sun Jan 5 17:30:16 UTC 2014 Modified Files: src/external/bsd/nvi/dist/vi: v_mark.c Log Message: PR/48502: M. Levinson: vi(1) no longer moves the cursor when yanking text using a mark (remove dangling else) To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/external/bsd/nvi/dist/vi/v_mark.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/nvi/dist/vi/v_mark.c diff -u src/external/bsd/nvi/dist/vi/v_mark.c:1.2 src/external/bsd/nvi/dist/vi/v_mark.c:1.3 --- src/external/bsd/nvi/dist/vi/v_mark.c:1.2 Fri Nov 22 10:52:06 2013 +++ src/external/bsd/nvi/dist/vi/v_mark.c Sun Jan 5 12:30:16 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: v_mark.c,v 1.2 2013/11/22 15:52:06 christos Exp $ */ +/* $NetBSD: v_mark.c,v 1.3 2014/01/05 17:30:16 christos Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -169,7 +169,7 @@ mark(SCR *sp, VICMD *vp, int getmark, en m = vp-m_start; vp-m_start = vp-m_stop; vp-m_stop = m; - } else + } /* * Yank cursor motion, when associated with marks as motion commands,
CVS commit: src/external/bsd/nvi/dist/vi
Module Name:src Committed By: mrg Date: Wed Nov 27 14:21:31 UTC 2013 Modified Files: src/external/bsd/nvi/dist/vi: vs_split.c Log Message: remove unused variable. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/external/bsd/nvi/dist/vi/vs_split.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/nvi/dist/vi/vs_split.c diff -u src/external/bsd/nvi/dist/vi/vs_split.c:1.3 src/external/bsd/nvi/dist/vi/vs_split.c:1.4 --- src/external/bsd/nvi/dist/vi/vs_split.c:1.3 Mon Nov 25 22:43:46 2013 +++ src/external/bsd/nvi/dist/vi/vs_split.c Wed Nov 27 14:21:31 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: vs_split.c,v 1.3 2013/11/25 22:43:46 christos Exp $ */ +/* $NetBSD: vs_split.c,v 1.4 2013/11/27 14:21:31 mrg Exp $ */ /*- * Copyright (c) 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -808,12 +808,10 @@ int vs_resize(SCR *sp, long int count, adj_t adj) { GS *gp; - WIN *wp; SCR *g, *s, *prev, *next, *list[3] = {NULL, NULL, NULL}; size_t g_off, s_off; gp = sp-gp; - wp = sp-wp; /* * Figure out which screens will grow, which will shrink, and
CVS commit: src/external/bsd/nvi/dist/vi
Module Name:src Committed By: christos Date: Thu Nov 28 03:15:20 UTC 2013 Modified Files: src/external/bsd/nvi/dist/vi: v_screen.c Log Message: fix bug in coversion To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/external/bsd/nvi/dist/vi/v_screen.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/nvi/dist/vi/v_screen.c diff -u src/external/bsd/nvi/dist/vi/v_screen.c:1.3 src/external/bsd/nvi/dist/vi/v_screen.c:1.4 --- src/external/bsd/nvi/dist/vi/v_screen.c:1.3 Mon Nov 25 17:43:46 2013 +++ src/external/bsd/nvi/dist/vi/v_screen.c Wed Nov 27 22:15:20 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: v_screen.c,v 1.3 2013/11/25 22:43:46 christos Exp $ */ +/* $NetBSD: v_screen.c,v 1.4 2013/11/28 03:15:20 christos Exp $ */ /*- * Copyright (c) 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -52,7 +52,7 @@ v_screen(SCR *sp, VICMD *vp) */ if (TAILQ_NEXT(sp, q) != NULL) sp-nextdisp = TAILQ_NEXT(sp, q); - else if (TAILQ_EMPTY(sp-wp-scrq)) { + else if (TAILQ_FIRST(sp-wp-scrq) == sp) { msgq(sp, M_ERR, 187|No other screen to switch to); return (1); } else
CVS commit: src/external/bsd/nvi/dist/vi
Module Name:src Committed By: christos Date: Tue Nov 26 16:48:01 UTC 2013 Modified Files: src/external/bsd/nvi/dist/vi: vs_msg.c vs_refresh.c Log Message: Avoid repainting after screen has been destroyed. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/external/bsd/nvi/dist/vi/vs_msg.c \ src/external/bsd/nvi/dist/vi/vs_refresh.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/nvi/dist/vi/vs_msg.c diff -u src/external/bsd/nvi/dist/vi/vs_msg.c:1.3 src/external/bsd/nvi/dist/vi/vs_msg.c:1.4 --- src/external/bsd/nvi/dist/vi/vs_msg.c:1.3 Mon Nov 25 17:43:46 2013 +++ src/external/bsd/nvi/dist/vi/vs_msg.c Tue Nov 26 11:48:01 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: vs_msg.c,v 1.3 2013/11/25 22:43:46 christos Exp $ */ +/* $NetBSD: vs_msg.c,v 1.4 2013/11/26 16:48:01 christos Exp $ */ /*- * Copyright (c) 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -661,6 +661,8 @@ vs_resolve(SCR *sp, SCR *csp, int forcew gp = sp-gp; wp = sp-wp; vip = VIP(sp); + if (vip == NULL) + return 0; if (csp == NULL) csp = sp; Index: src/external/bsd/nvi/dist/vi/vs_refresh.c diff -u src/external/bsd/nvi/dist/vi/vs_refresh.c:1.3 src/external/bsd/nvi/dist/vi/vs_refresh.c:1.4 --- src/external/bsd/nvi/dist/vi/vs_refresh.c:1.3 Mon Nov 25 17:43:46 2013 +++ src/external/bsd/nvi/dist/vi/vs_refresh.c Tue Nov 26 11:48:01 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: vs_refresh.c,v 1.3 2013/11/25 22:43:46 christos Exp $ */ +/* $NetBSD: vs_refresh.c,v 1.4 2013/11/26 16:48:01 christos Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -81,7 +81,8 @@ vs_refresh(SCR *sp, int forcepaint) (void)vs_paint(tsp, (F_ISSET(VIP(tsp), VIP_CUR_INVALID) ? UPDATE_CURSOR : 0) | UPDATE_SCREEN); - F_SET(VIP(sp), VIP_CUR_INVALID); + if (VIP(sp)) +F_SET(VIP(sp), VIP_CUR_INVALID); } /* @@ -155,6 +156,8 @@ vs_paint(SCR *sp, u_int flags) gp = sp-gp; vip = VIP(sp); + if (vip == NULL) + return 0; didpaint = leftright_warp = 0; /*