aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2021-03-22 14:34:14 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2021-03-22 14:34:14 +0000
commitf9a159da2a292968cd5c37b56a6c43b6af8c5eed (patch)
tree6068c188fd0adbf0cfbc185d62250f6bd08960db /contrib
parenta0409676120c1e558d0ade943019934e0f15118d (diff)
parent881fcf9c3caf82a2f97a17b6ca91eb0b1b0320cd (diff)
downloadsrc-f9a159da2a292968cd5c37b56a6c43b6af8c5eed.tar.gz
src-f9a159da2a292968cd5c37b56a6c43b6af8c5eed.zip
libedit: vendor import snapshot 2020-07-10
Diffstat (limited to 'contrib')
-rw-r--r--contrib/libedit/Makefile6
-rw-r--r--contrib/libedit/chartype.h2
-rw-r--r--contrib/libedit/common.c8
-rw-r--r--contrib/libedit/filecomplete.c221
-rw-r--r--contrib/libedit/history.c14
-rw-r--r--contrib/libedit/map.c10
-rw-r--r--contrib/libedit/readline.c18
-rw-r--r--contrib/libedit/refresh.c5
-rw-r--r--contrib/libedit/search.c26
-rw-r--r--contrib/libedit/terminal.c61
-rw-r--r--contrib/libedit/tty.c7
11 files changed, 196 insertions, 182 deletions
diff --git a/contrib/libedit/Makefile b/contrib/libedit/Makefile
index 8a02211504a8..105a6a92e0ee 100644
--- a/contrib/libedit/Makefile
+++ b/contrib/libedit/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.65 2017/06/30 20:26:52 kre Exp $
+# $NetBSD: Makefile,v 1.66 2019/10/13 07:28:10 mrg Exp $
# @(#)Makefile 8.1 (Berkeley) 6/4/93
USE_SHLIBDIR= yes
@@ -137,3 +137,7 @@ COPTS.literal.c+= -Wno-sign-conversion
COPTS.tokenizer.c+= -Wno-cast-qual
COPTS.tokenizern.c+= -Wno-cast-qual
.endif
+
+COPTS.history.c+= ${GCC_NO_STRINGOP_OVERFLOW}
+COPTS.historyn.c+= ${GCC_NO_STRINGOP_OVERFLOW}
+COPTS.readline.c+= ${GCC_NO_STRINGOP_TRUNCATION} ${GCC_NO_STRINGOP_OVERFLOW}
diff --git a/contrib/libedit/chartype.h b/contrib/libedit/chartype.h
index 3eda7da07296..bfa3d54ec36c 100644
--- a/contrib/libedit/chartype.h
+++ b/contrib/libedit/chartype.h
@@ -1,4 +1,4 @@
-/* $NetBSD: chartype.h,v 1.35 2017/05/22 19:16:25 christos Exp $ */
+/* $NetBSD: chartype.h,v 1.36 2019/09/15 21:09:11 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
diff --git a/contrib/libedit/common.c b/contrib/libedit/common.c
index bc6c057cf51d..f33c29650d79 100644
--- a/contrib/libedit/common.c
+++ b/contrib/libedit/common.c
@@ -1,4 +1,4 @@
-/* $NetBSD: common.c,v 1.48 2018/02/26 17:36:14 christos Exp $ */
+/* $NetBSD: common.c,v 1.49 2020/03/30 06:54:37 ryo Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: common.c,v 1.48 2018/02/26 17:36:14 christos Exp $");
+__RCSID("$NetBSD: common.c,v 1.49 2020/03/30 06:54:37 ryo Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -658,7 +658,7 @@ ed_search_prev_history(EditLine *el, wint_t c __attribute__((__unused__)))
while (hp != NULL) {
#ifdef SDEBUG
- (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);
+ (void) fprintf(el->el_errfile, "Comparing with \"%ls\"\n", hp);
#endif
if ((wcsncmp(hp, el->el_line.buffer, (size_t)
(el->el_line.lastchar - el->el_line.buffer)) ||
@@ -713,7 +713,7 @@ ed_search_next_history(EditLine *el, wint_t c __attribute__((__unused__)))
for (h = 1; h < el->el_history.eventno && hp; h++) {
#ifdef SDEBUG
- (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);
+ (void) fprintf(el->el_errfile, "Comparing with \"%ls\"\n", hp);
#endif
if ((wcsncmp(hp, el->el_line.buffer, (size_t)
(el->el_line.lastchar - el->el_line.buffer)) ||
diff --git a/contrib/libedit/filecomplete.c b/contrib/libedit/filecomplete.c
index 662a0bb85d0b..61579024926c 100644
--- a/contrib/libedit/filecomplete.c
+++ b/contrib/libedit/filecomplete.c
@@ -1,4 +1,4 @@
-/* $NetBSD: filecomplete.c,v 1.58 2019/09/08 05:50:58 abhinav Exp $ */
+/* $NetBSD: filecomplete.c,v 1.64 2020/01/05 07:12:05 abhinav Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: filecomplete.c,v 1.58 2019/09/08 05:50:58 abhinav Exp $");
+__RCSID("$NetBSD: filecomplete.c,v 1.64 2020/01/05 07:12:05 abhinav Exp $");
#endif /* not lint && not SCCSID */
#include <sys/types.h>
@@ -86,8 +86,7 @@ fn_tilde_expand(const char *txt)
temp = el_calloc(len, sizeof(*temp));
if (temp == NULL)
return NULL;
- (void)strncpy(temp, txt + 1, len - 2);
- temp[len - 2] = '\0';
+ (void)strlcpy(temp, txt + 1, len - 1);
}
if (temp[0] == 0) {
#ifdef HAVE_GETPW_R_POSIX
@@ -354,8 +353,7 @@ fn_filename_completion_function(const char *text, int state)
return NULL;
}
dirname = nptr;
- (void)strncpy(dirname, text, len);
- dirname[len] = '\0';
+ (void)strlcpy(dirname, text, len + 1);
} else {
el_free(filename);
if (*text == 0)
@@ -509,8 +507,7 @@ completion_matches(const char *text, char *(*genfunc)(const char *, int))
el_free(match_list);
return NULL;
}
- (void)strncpy(retstr, match_list[1], max_equal);
- retstr[max_equal] = '\0';
+ (void)strlcpy(retstr, match_list[1], max_equal + 1);
match_list[0] = retstr;
/* add NULL as last pointer to the array */
@@ -586,10 +583,12 @@ fn_display_match_list(EditLine * el, char **matches, size_t num, size_t width,
static wchar_t *
find_word_to_complete(const wchar_t * cursor, const wchar_t * buffer,
- const wchar_t * word_break, const wchar_t * special_prefixes, size_t * length)
+ const wchar_t * word_break, const wchar_t * special_prefixes, size_t * length,
+ int do_unescape)
{
/* We now look backwards for the start of a filename/variable word */
const wchar_t *ctemp = cursor;
+ wchar_t *temp;
size_t len;
/* if the cursor is placed at a slash or a quote, we need to find the
@@ -614,12 +613,8 @@ find_word_to_complete(const wchar_t * cursor, const wchar_t * buffer,
if (ctemp - buffer >= 2 && ctemp[-2] == '\\') {
ctemp -= 2;
continue;
- } else if (ctemp - buffer >= 2 &&
- (ctemp[-2] == '\'' || ctemp[-2] == '"')) {
- ctemp--;
- continue;
- } else
- break;
+ }
+ break;
}
if (special_prefixes && wcschr(special_prefixes, ctemp[-1]))
break;
@@ -632,10 +627,16 @@ find_word_to_complete(const wchar_t * cursor, const wchar_t * buffer,
ctemp++;
}
*length = len;
- wchar_t *unescaped_word = unescape_string(ctemp, len);
- if (unescaped_word == NULL)
- return NULL;
- return unescaped_word;
+ if (do_unescape) {
+ wchar_t *unescaped_word = unescape_string(ctemp, len);
+ if (unescaped_word == NULL)
+ return NULL;
+ return unescaped_word;
+ }
+ temp = el_malloc((len + 1) * sizeof(*temp));
+ (void) wcsncpy(temp, ctemp, len);
+ temp[len] = '\0';
+ return temp;
}
/*
@@ -665,6 +666,7 @@ fn_complete(EditLine *el,
size_t len;
int what_to_do = '\t';
int retval = CC_NORM;
+ int do_unescape = attempted_completion_function == NULL? 1: 0;
if (el->el_state.lastcmd == el->el_state.thiscmd)
what_to_do = '?';
@@ -680,7 +682,7 @@ fn_complete(EditLine *el,
li = el_wline(el);
temp = find_word_to_complete(li->cursor,
- li->buffer, word_break, special_prefixes, &len);
+ li->buffer, word_break, special_prefixes, &len, do_unescape);
if (temp == NULL)
goto out;
@@ -706,107 +708,110 @@ fn_complete(EditLine *el,
if (over != NULL)
*over = 0;
- if (matches) {
- int i;
- size_t matches_num, maxlen, match_len, match_display=1;
- int single_match = matches[2] == NULL &&
- (matches[1] == NULL || strcmp(matches[0], matches[1]) == 0);
-
- retval = CC_REFRESH;
-
- if (matches[0][0] != '\0') {
- el_deletestr(el, (int)len);
- if (!attempted_completion_function)
- completion = escape_filename(el, matches[0],
- single_match, app_func);
- else
- completion = strdup(matches[0]);
- if (completion == NULL)
- goto out;
- if (single_match) {
- /* We found exact match. Add a space after it,
- * unless we do filename completion and the
- * object is a directory. Also do necessary
- * escape quoting
- */
- el_winsertstr(el,
- ct_decode_string(completion, &el->el_scratch));
- } else {
- /* Only replace the completed string with
- * common part of possible matches if there is
- * possible completion.
- */
- el_winsertstr(el,
- ct_decode_string(completion, &el->el_scratch));
- }
- free(completion);
- }
+ if (matches == NULL) {
+ goto out;
+ }
+ int i;
+ size_t matches_num, maxlen, match_len, match_display=1;
+ int single_match = matches[2] == NULL &&
+ (matches[1] == NULL || strcmp(matches[0], matches[1]) == 0);
+
+ retval = CC_REFRESH;
+
+ if (matches[0][0] != '\0') {
+ el_deletestr(el, (int)len);
+ if (!attempted_completion_function)
+ completion = escape_filename(el, matches[0],
+ single_match, app_func);
+ else
+ completion = strdup(matches[0]);
+ if (completion == NULL)
+ goto out;
+ /*
+ * Replace the completed string with the common part of
+ * all possible matches if there is a possible completion.
+ */
+ el_winsertstr(el,
+ ct_decode_string(completion, &el->el_scratch));
- if (!single_match && (what_to_do == '!' || what_to_do == '?')) {
+ if (single_match && attempted_completion_function) {
/*
- * More than one match and requested to list possible
- * matches.
+ * We found an exact match. Add a space after
+ * it, unless we do filename completion and the
+ * object is a directory. Also do necessary
+ * escape quoting
*/
+ el_winsertstr(el, ct_decode_string(
+ (*app_func)(completion), &el->el_scratch));
+ }
+ free(completion);
+ }
- for(i = 1, maxlen = 0; matches[i]; i++) {
- match_len = strlen(matches[i]);
- if (match_len > maxlen)
- maxlen = match_len;
- }
- /* matches[1] through matches[i-1] are available */
- matches_num = (size_t)(i - 1);
- /* newline to get on next line from command line */
- (void)fprintf(el->el_outfile, "\n");
+ if (!single_match && (what_to_do == '!' || what_to_do == '?')) {
+ /*
+ * More than one match and requested to list possible
+ * matches.
+ */
- /*
- * If there are too many items, ask user for display
- * confirmation.
- */
- if (matches_num > query_items) {
- (void)fprintf(el->el_outfile,
- "Display all %zu possibilities? (y or n) ",
- matches_num);
- (void)fflush(el->el_outfile);
- if (getc(stdin) != 'y')
- match_display = 0;
- (void)fprintf(el->el_outfile, "\n");
- }
+ for(i = 1, maxlen = 0; matches[i]; i++) {
+ match_len = strlen(matches[i]);
+ if (match_len > maxlen)
+ maxlen = match_len;
+ }
+ /* matches[1] through matches[i-1] are available */
+ matches_num = (size_t)(i - 1);
- if (match_display) {
- /*
- * Interface of this function requires the
- * strings be matches[1..num-1] for compat.
- * We have matches_num strings not counting
- * the prefix in matches[0], so we need to
- * add 1 to matches_num for the call.
- */
- fn_display_match_list(el, matches,
- matches_num+1, maxlen, app_func);
- }
- retval = CC_REDISPLAY;
- } else if (matches[0][0]) {
+ /* newline to get on next line from command line */
+ (void)fprintf(el->el_outfile, "\n");
+
+ /*
+ * If there are too many items, ask user for display
+ * confirmation.
+ */
+ if (matches_num > query_items) {
+ (void)fprintf(el->el_outfile,
+ "Display all %zu possibilities? (y or n) ",
+ matches_num);
+ (void)fflush(el->el_outfile);
+ if (getc(stdin) != 'y')
+ match_display = 0;
+ (void)fprintf(el->el_outfile, "\n");
+ }
+
+ if (match_display) {
/*
- * There was some common match, but the name was
- * not complete enough. Next tab will print possible
- * completions.
+ * Interface of this function requires the
+ * strings be matches[1..num-1] for compat.
+ * We have matches_num strings not counting
+ * the prefix in matches[0], so we need to
+ * add 1 to matches_num for the call.
*/
- el_beep(el);
- } else {
- /* lcd is not a valid object - further specification */
- /* is needed */
- el_beep(el);
- retval = CC_NORM;
+ fn_display_match_list(el, matches,
+ matches_num+1, maxlen, app_func);
}
-
- /* free elements of array and the array itself */
- for (i = 0; matches[i]; i++)
- el_free(matches[i]);
- el_free(matches);
- matches = NULL;
+ retval = CC_REDISPLAY;
+ } else if (matches[0][0]) {
+ /*
+ * There was some common match, but the name was
+ * not complete enough. Next tab will print possible
+ * completions.
+ */
+ el_beep(el);
+ } else {
+ /* lcd is not a valid object - further specification */
+ /* is needed */
+ el_beep(el);
+ retval = CC_NORM;
}
+ /* free elements of array and the array itself */
+ for (i = 0; matches[i]; i++)
+ el_free(matches[i]);
+ el_free(matches);
+ matches = NULL;
+
out:
el_free(temp);
return retval;
diff --git a/contrib/libedit/history.c b/contrib/libedit/history.c
index 227f72c4a102..73cfa6b8ead9 100644
--- a/contrib/libedit/history.c
+++ b/contrib/libedit/history.c
@@ -1,4 +1,4 @@
-/* $NetBSD: history.c,v 1.62 2018/09/13 09:03:40 kre Exp $ */
+/* $NetBSD: history.c,v 1.63 2019/10/08 19:17:57 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: history.c,v 1.62 2018/09/13 09:03:40 kre Exp $");
+__RCSID("$NetBSD: history.c,v 1.63 2019/10/08 19:17:57 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -411,21 +411,23 @@ static int
history_def_add(void *p, TYPE(HistEvent) *ev, const Char *str)
{
history_t *h = (history_t *) p;
- size_t len;
+ size_t len, elen, slen;
Char *s;
HistEventPrivate *evp = (void *)&h->cursor->ev;
if (h->cursor == &h->list)
return history_def_enter(p, ev, str);
- len = Strlen(evp->str) + Strlen(str) + 1;
+ elen = Strlen(evp->str);
+ slen = Strlen(str);
+ len = elen + slen + 1;
s = h_malloc(len * sizeof(*s));
if (s == NULL) {
he_seterrev(ev, _HE_MALLOC_FAILED);
return -1;
}
- (void) Strncpy(s, h->cursor->ev.str, len);
+ memcpy(s, evp->str, elen * sizeof(*s));
+ memcpy(s + elen, str, slen * sizeof(*s));
s[len - 1] = '\0';
- (void) Strncat(s, str, len - Strlen(s) - 1);
h_free(evp->str);
evp->str = s;
*ev = h->cursor->ev;
diff --git a/contrib/libedit/map.c b/contrib/libedit/map.c
index 0c489593335a..46bf6f1c9472 100644
--- a/contrib/libedit/map.c
+++ b/contrib/libedit/map.c
@@ -1,4 +1,4 @@
-/* $NetBSD: map.c,v 1.52 2019/07/23 10:18:52 christos Exp $ */
+/* $NetBSD: map.c,v 1.53 2020/03/30 06:54:37 ryo Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: map.c,v 1.52 2019/07/23 10:18:52 christos Exp $");
+__RCSID("$NetBSD: map.c,v 1.53 2020/03/30 06:54:37 ryo Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -906,11 +906,11 @@ map_init(EditLine *el)
*/
#ifdef MAP_DEBUG
if (sizeof(el_map_emacs) != N_KEYS * sizeof(el_action_t))
- EL_ABORT((el->errfile, "Emacs map incorrect\n"));
+ EL_ABORT((el->el_errfile, "Emacs map incorrect\n"));
if (sizeof(el_map_vi_command) != N_KEYS * sizeof(el_action_t))
- EL_ABORT((el->errfile, "Vi command map incorrect\n"));
+ EL_ABORT((el->el_errfile, "Vi command map incorrect\n"));
if (sizeof(el_map_vi_insert) != N_KEYS * sizeof(el_action_t))
- EL_ABORT((el->errfile, "Vi insert map incorrect\n"));
+ EL_ABORT((el->el_errfile, "Vi insert map incorrect\n"));
#endif
el->el_map.alt = el_calloc(N_KEYS, sizeof(*el->el_map.alt));
diff --git a/contrib/libedit/readline.c b/contrib/libedit/readline.c
index dc852f5539c1..792dddbaf70b 100644
--- a/contrib/libedit/readline.c
+++ b/contrib/libedit/readline.c
@@ -1,4 +1,4 @@
-/* $NetBSD: readline.c,v 1.157 2019/08/21 11:11:48 christos Exp $ */
+/* $NetBSD: readline.c,v 1.159 2019/10/09 14:31:07 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: readline.c,v 1.157 2019/08/21 11:11:48 christos Exp $");
+__RCSID("$NetBSD: readline.c,v 1.159 2019/10/09 14:31:07 christos Exp $");
#endif /* not lint && not SCCSID */
#include <sys/types.h>
@@ -521,7 +521,7 @@ _rl_compat_sub(const char *str, const char *what, const char *with,
s = str;
while (*s) {
if (*s == *what && !strncmp(s, what, what_len)) {
- (void)strncpy(r, with, with_len);
+ memcpy(r, with, with_len);
r += with_len;
s += what_len;
if (!globally) {
@@ -607,8 +607,7 @@ get_history_event(const char *cmd, int *cindex, int qchar)
else {
if ((pat = el_calloc(len + 1, sizeof(*pat))) == NULL)
return NULL;
- (void)strncpy(pat, cmd + begin, len);
- pat[len] = '\0';
+ (void)strlcpy(pat, cmd + begin, len + 1);
}
if (history(h, &ev, H_CURR) != 0) {
@@ -702,8 +701,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
if ((aptr = el_calloc(offs + 1, sizeof(*aptr)))
== NULL)
return -1;
- (void)strncpy(aptr, command, offs);
- aptr[offs] = '\0';
+ (void)strlcpy(aptr, command, offs + 1);
idx = 1;
} else {
int qchar;
@@ -960,9 +958,8 @@ history_expand(char *str, char **output)
} \
result = nresult; \
} \
- (void)strncpy(&result[idx], what, len); \
+ (void)strlcpy(&result[idx], what, len + 1); \
idx += len; \
- result[idx] = '\0'; \
}
result = NULL;
@@ -1150,8 +1147,7 @@ history_tokenize(const char *str)
el_free(result);
return NULL;
}
- (void)strncpy(temp, &str[start], len);
- temp[len] = '\0';
+ (void)strlcpy(temp, &str[start], len + 1);
result[idx++] = temp;
result[idx] = NULL;
if (str[i])
diff --git a/contrib/libedit/refresh.c b/contrib/libedit/refresh.c
index 584eec624976..fab29746478c 100644
--- a/contrib/libedit/refresh.c
+++ b/contrib/libedit/refresh.c
@@ -1,4 +1,4 @@
-/* $NetBSD: refresh.c,v 1.56 2019/01/04 03:03:44 uwe Exp $ */
+/* $NetBSD: refresh.c,v 1.57 2020/03/30 06:54:37 ryo Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: refresh.c,v 1.56 2019/01/04 03:03:44 uwe Exp $");
+__RCSID("$NetBSD: refresh.c,v 1.57 2020/03/30 06:54:37 ryo Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -45,6 +45,7 @@ __RCSID("$NetBSD: refresh.c,v 1.56 2019/01/04 03:03:44 uwe Exp $");
* refresh.c: Lower level screen refreshing functions
*/
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
diff --git a/contrib/libedit/search.c b/contrib/libedit/search.c
index 78e15d720cb8..e909d1475725 100644
--- a/contrib/libedit/search.c
+++ b/contrib/libedit/search.c
@@ -1,4 +1,4 @@
-/* $NetBSD: search.c,v 1.49 2019/07/23 10:18:52 christos Exp $ */
+/* $NetBSD: search.c,v 1.51 2020/03/30 06:56:38 ryo Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: search.c,v 1.49 2019/07/23 10:18:52 christos Exp $");
+__RCSID("$NetBSD: search.c,v 1.51 2020/03/30 06:56:38 ryo Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -162,7 +162,7 @@ libedit_private int
c_hmatch(EditLine *el, const wchar_t *str)
{
#ifdef SDEBUG
- (void) fprintf(el->el_errfile, "match `%s' with `%s'\n",
+ (void) fprintf(el->el_errfile, "match `%ls' with `%ls'\n",
el->el_search.patbuf, str);
#endif /* SDEBUG */
@@ -182,20 +182,17 @@ c_setpat(EditLine *el)
(size_t)(EL_CURSOR(el) - el->el_line.buffer);
if (el->el_search.patlen >= EL_BUFSIZ)
el->el_search.patlen = EL_BUFSIZ - 1;
- if (el->el_search.patlen != 0) {
- (void) wcsncpy(el->el_search.patbuf, el->el_line.buffer,
- el->el_search.patlen);
- el->el_search.patbuf[el->el_search.patlen] = '\0';
- } else
- el->el_search.patlen = wcslen(el->el_search.patbuf);
+ (void) wcsncpy(el->el_search.patbuf, el->el_line.buffer,
+ el->el_search.patlen);
+ el->el_search.patbuf[el->el_search.patlen] = '\0';
}
#ifdef SDEBUG
(void) fprintf(el->el_errfile, "\neventno = %d\n",
el->el_history.eventno);
- (void) fprintf(el->el_errfile, "patlen = %d\n", el->el_search.patlen);
- (void) fprintf(el->el_errfile, "patbuf = \"%s\"\n",
+ (void) fprintf(el->el_errfile, "patlen = %ld\n", el->el_search.patlen);
+ (void) fprintf(el->el_errfile, "patbuf = \"%ls\"\n",
el->el_search.patbuf);
- (void) fprintf(el->el_errfile, "cursor %d lastchar %d\n",
+ (void) fprintf(el->el_errfile, "cursor %ld lastchar %ld\n",
EL_CURSOR(el) - el->el_line.buffer,
el->el_line.lastchar - el->el_line.buffer);
#endif
@@ -573,8 +570,9 @@ cv_repeat_srch(EditLine *el, wint_t c)
{
#ifdef SDEBUG
- (void) fprintf(el->el_errfile, "dir %d patlen %d patbuf %s\n",
- c, el->el_search.patlen, ct_encode_string(el->el_search.patbuf));
+ static ct_buffer_t conv;
+ (void) fprintf(el->el_errfile, "dir %d patlen %ld patbuf %s\n",
+ c, el->el_search.patlen, ct_encode_string(el->el_search.patbuf, &conv));
#endif
el->el_state.lastcmd = (el_action_t) c; /* Hack to stop c_setpat */
diff --git a/contrib/libedit/terminal.c b/contrib/libedit/terminal.c
index 34f4985a90bc..b3ab5bfb6244 100644
--- a/contrib/libedit/terminal.c
+++ b/contrib/libedit/terminal.c
@@ -1,4 +1,4 @@
-/* $NetBSD: terminal.c,v 1.39 2019/07/23 10:18:52 christos Exp $ */
+/* $NetBSD: terminal.c,v 1.43 2020/07/10 20:34:24 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95";
#else
-__RCSID("$NetBSD: terminal.c,v 1.39 2019/07/23 10:18:52 christos Exp $");
+__RCSID("$NetBSD: terminal.c,v 1.43 2020/07/10 20:34:24 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -497,7 +497,7 @@ terminal_move_to_line(EditLine *el, int where)
if (where == el->el_cursor.v)
return;
- if (where > el->el_terminal.t_size.v) {
+ if (where >= el->el_terminal.t_size.v) {
#ifdef DEBUG_SCREEN
(void) fprintf(el->el_errfile,
"%s: where is ridiculous: %d\r\n", __func__, where);
@@ -647,7 +647,8 @@ terminal_overwrite(EditLine *el, const wchar_t *cp, size_t n)
if (el->el_cursor.h >= el->el_terminal.t_size.h) { /* wrap? */
if (EL_HAS_AUTO_MARGINS) { /* yes */
el->el_cursor.h = 0;
- el->el_cursor.v++;
+ if (el->el_cursor.v + 1 < el->el_terminal.t_size.v)
+ el->el_cursor.v++;
if (EL_HAS_MAGIC_MARGINS) {
/* force the wrap to avoid the "magic"
* situation */
@@ -1314,14 +1315,14 @@ terminal_settc(EditLine *el, int argc __attribute__((__unused__)),
const struct termcapstr *ts;
const struct termcapval *tv;
char what[8], how[8];
+ long i;
+ char *ep;
if (argv == NULL || argv[1] == NULL || argv[2] == NULL)
return -1;
- strncpy(what, ct_encode_string(argv[1], &el->el_scratch), sizeof(what));
- what[sizeof(what) - 1] = '\0';
- strncpy(how, ct_encode_string(argv[2], &el->el_scratch), sizeof(how));
- how[sizeof(how) - 1] = '\0';
+ strlcpy(what, ct_encode_string(argv[1], &el->el_scratch), sizeof(what));
+ strlcpy(how, ct_encode_string(argv[2], &el->el_scratch), sizeof(how));
/*
* Do the strings first
@@ -1342,11 +1343,17 @@ terminal_settc(EditLine *el, int argc __attribute__((__unused__)),
if (strcmp(tv->name, what) == 0)
break;
- if (tv->name != NULL)
+ if (tv->name == NULL) {
+ (void) fprintf(el->el_errfile,
+ "%ls: Bad capability `%s'.\n", argv[0], what);
return -1;
+ }
if (tv == &tval[T_pt] || tv == &tval[T_km] ||
tv == &tval[T_am] || tv == &tval[T_xn]) {
+ /*
+ * Booleans
+ */
if (strcmp(how, "yes") == 0)
el->el_terminal.t_val[tv - tval] = 1;
else if (strcmp(how, "no") == 0)
@@ -1357,28 +1364,30 @@ terminal_settc(EditLine *el, int argc __attribute__((__unused__)),
return -1;
}
terminal_setflags(el);
- if (terminal_change_size(el, Val(T_li), Val(T_co)) == -1)
- return -1;
return 0;
- } else {
- long i;
- char *ep;
+ }
- i = strtol(how, &ep, 10);
- if (*ep != '\0') {
- (void) fprintf(el->el_errfile,
- "%ls: Bad value `%s'.\n", argv[0], how);
- return -1;
- }
- el->el_terminal.t_val[tv - tval] = (int) i;
+ /*
+ * Numerics
+ */
+ i = strtol(how, &ep, 10);
+ if (*ep != '\0') {
+ (void) fprintf(el->el_errfile,
+ "%ls: Bad value `%s'.\n", argv[0], how);
+ return -1;
+ }
+ el->el_terminal.t_val[tv - tval] = (int) i;
+ i = 0;
+ if (tv == &tval[T_co]) {
el->el_terminal.t_size.v = Val(T_co);
+ i++;
+ } else if (tv == &tval[T_li]) {
el->el_terminal.t_size.h = Val(T_li);
- if (tv == &tval[T_co] || tv == &tval[T_li])
- if (terminal_change_size(el, Val(T_li), Val(T_co))
- == -1)
- return -1;
- return 0;
+ i++;
}
+ if (i && terminal_change_size(el, Val(T_li), Val(T_co)) == -1)
+ return -1;
+ return 0;
}
diff --git a/contrib/libedit/tty.c b/contrib/libedit/tty.c
index 743075e08b3f..bafc906ccc4e 100644
--- a/contrib/libedit/tty.c
+++ b/contrib/libedit/tty.c
@@ -1,4 +1,4 @@
-/* $NetBSD: tty.c,v 1.68 2018/12/02 16:58:13 christos Exp $ */
+/* $NetBSD: tty.c,v 1.69 2020/05/31 23:24:23 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: tty.c,v 1.68 2018/12/02 16:58:13 christos Exp $");
+__RCSID("$NetBSD: tty.c,v 1.69 2020/05/31 23:24:23 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -1163,8 +1163,7 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)),
if (argv == NULL)
return -1;
- strncpy(name, ct_encode_string(*argv++, &el->el_scratch), sizeof(name));
- name[sizeof(name) - 1] = '\0';
+ strlcpy(name, ct_encode_string(*argv++, &el->el_scratch), sizeof(name));
while (argv && *argv && argv[0][0] == '-' && argv[0][2] == '\0')
switch (argv[0][1]) {