mirror of
https://git.FreeBSD.org/src.git
synced 2025-02-06 18:29:47 +00:00
libedit: Use correct buffer lengths in vi mode v command.
Libedit's vi mode provides a v command to edit the current line in vi(1) (hard-coded to vi, in fact). When Unicode/wide character mode was added, this command started truncating and/or corrupting the edited text. This commit fixes v if the text fits into the buffer. If the text is longer, it is truncated. PR: 203743 Obtained from: NetBSD (originally submitted by me)
This commit is contained in:
parent
75908e8a23
commit
f1d04a2543
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=290065
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: vi.c,v 1.45 2014/06/18 18:12:28 christos Exp $ */
|
||||
/* $NetBSD: vi.c,v 1.47 2015/10/21 21:45:30 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -42,7 +42,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: vi.c,v 1.45 2014/06/18 18:12:28 christos Exp $");
|
||||
__RCSID("$NetBSD: vi.c,v 1.47 2015/10/21 21:45:30 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
#include <sys/cdefs.h>
|
||||
@ -1040,12 +1040,12 @@ vi_histedit(EditLine *el, Int c __attribute__((__unused__)))
|
||||
while (waitpid(pid, &status, 0) != pid)
|
||||
continue;
|
||||
lseek(fd, (off_t)0, SEEK_SET);
|
||||
st = read(fd, cp, TMP_BUFSIZ);
|
||||
st = read(fd, cp, TMP_BUFSIZ - 1);
|
||||
if (st > 0) {
|
||||
len = (size_t)(el->el_line.lastchar -
|
||||
el->el_line.buffer);
|
||||
cp[st] = '\0';
|
||||
len = (size_t)(el->el_line.limit - el->el_line.buffer);
|
||||
len = ct_mbstowcs(el->el_line.buffer, cp, len);
|
||||
if (len > 0 && el->el_line.buffer[len -1] == '\n')
|
||||
if (len > 0 && el->el_line.buffer[len - 1] == '\n')
|
||||
--len;
|
||||
}
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user