From f9ff2f8ffbd083eb96c7fb0e0a7bd0daa6d70495 Mon Sep 17 00:00:00 2001 From: Stefan Farfeleder Date: Sun, 11 Mar 2007 21:47:40 +0000 Subject: [PATCH] Merge the following changes from NetBSD: history.c 1.32: # Fix memory leak found by valgrind (Julien Torres) map.c 1.24: # fix debugging printf format. read.c 1.40: # Fix bug with multiple pending el_pushes. Reported by Julien Torres. tty.c 1.24: # Coverity CID 1216: Prevent negative index use. MFC after: 3 weeks --- lib/libedit/history.c | 3 ++- lib/libedit/map.c | 4 ++-- lib/libedit/read.c | 32 ++++++++++++++++++++++++-------- lib/libedit/tty.c | 14 +++++++++----- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/lib/libedit/history.c b/lib/libedit/history.c index af4892a92a21..76b3b076d811 100644 --- a/lib/libedit/history.c +++ b/lib/libedit/history.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $NetBSD: history.c,v 1.31 2005/08/01 14:34:06 christos Exp $ + * $NetBSD: history.c,v 1.32 2006/09/28 13:52:51 christos Exp $ */ #if !defined(lint) && !defined(SCCSID) @@ -543,6 +543,7 @@ history_end(History *h) if (h->h_next == history_def_next) history_def_clear(h->h_ref, &ev); + h_free(h->h_ref); h_free(h); } diff --git a/lib/libedit/map.c b/lib/libedit/map.c index c4121a633801..591118f2cf02 100644 --- a/lib/libedit/map.c +++ b/lib/libedit/map.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $NetBSD: map.c,v 1.23 2006/03/06 21:11:56 christos Exp $ + * $NetBSD: map.c,v 1.24 2006/04/09 01:36:51 christos Exp $ */ #if !defined(lint) && !defined(SCCSID) @@ -1381,7 +1381,7 @@ map_bind(EditLine *el, int argc, const char **argv) break; default: - EL_ABORT((el->el_errfile, "Bad XK_ type\n", ntype)); + EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype)); break; } return (0); diff --git a/lib/libedit/read.c b/lib/libedit/read.c index 4d0b39460cfe..f774217279f5 100644 --- a/lib/libedit/read.c +++ b/lib/libedit/read.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $NetBSD: read.c,v 1.39 2005/08/02 12:11:14 christos Exp $ + * $NetBSD: read.c,v 1.40 2007/03/01 21:41:45 christos Exp $ */ #if !defined(lint) && !defined(SCCSID) @@ -55,6 +55,7 @@ private int read__fixio(int, int); private int read_preread(EditLine *); private int read_char(EditLine *, char *); private int read_getcmd(EditLine *, el_action_t *, char *); +private void read_pop(c_macro_t *); /* read_init(): * Initialize the read stuff @@ -299,6 +300,19 @@ read_char(EditLine *el, char *cp) return (num_read); } +/* read_pop(): + * Pop a macro from the stack + */ +private void +read_pop(c_macro_t *ma) +{ + int i; + + el_free(ma->macro[0]); + for (i = ma->level--; i > 0; i--) + ma->macro[i - 1] = ma->macro[i]; + ma->offset = 0; +} /* el_getc(): * Read a character @@ -315,20 +329,22 @@ el_getc(EditLine *el, char *cp) if (!read_preread(el)) break; } + if (ma->level < 0) break; - if (ma->macro[ma->level][ma->offset] == '\0') { - el_free(ma->macro[ma->level--]); - ma->offset = 0; + if (ma->macro[0][ma->offset] == '\0') { + read_pop(ma); continue; } - *cp = ma->macro[ma->level][ma->offset++] & 0377; - if (ma->macro[ma->level][ma->offset] == '\0') { + + *cp = ma->macro[0][ma->offset++] & 0377; + + if (ma->macro[0][ma->offset] == '\0') { /* Needed for QuoteMode On */ - el_free(ma->macro[ma->level--]); - ma->offset = 0; + read_pop(ma); } + return (1); } diff --git a/lib/libedit/tty.c b/lib/libedit/tty.c index e2b99327ea96..fca3c2bbe1d0 100644 --- a/lib/libedit/tty.c +++ b/lib/libedit/tty.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $NetBSD: tty.c,v 1.23 2005/06/01 11:37:52 lukem Exp $ + * $NetBSD: tty.c,v 1.24 2006/03/18 09:07:05 christos Exp $ */ #if !defined(lint) && !defined(SCCSID) @@ -1149,10 +1149,14 @@ tty_stty(EditLine *el, int argc __unused, const char **argv) st = len = strlen(el->el_tty.t_t[z][m->m_type].t_name); } - x = (el->el_tty.t_t[z][i].t_setmask & m->m_value) - ? '+' : '\0'; - x = (el->el_tty.t_t[z][i].t_clrmask & m->m_value) - ? '-' : x; + if (i != -1) { + x = (el->el_tty.t_t[z][i].t_setmask & m->m_value) + ? '+' : '\0'; + x = (el->el_tty.t_t[z][i].t_clrmask & m->m_value) + ? '-' : x; + } else { + x = '\0'; + } if (x != '\0' || aflag) {