Sun Mar 5 19:23:58 2017 UTC ()
one extra char for NUL.


(christos)
diff -r1.31 -r1.32 src/lib/libedit/hist.c

cvs diff -r1.31 -r1.32 src/lib/libedit/hist.c (expand / switch to unified diff)

--- src/lib/libedit/hist.c 2017/03/05 17:30:38 1.31
+++ src/lib/libedit/hist.c 2017/03/05 19:23:58 1.32
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: hist.c,v 1.31 2017/03/05 17:30:38 christos Exp $ */ 1/* $NetBSD: hist.c,v 1.32 2017/03/05 19:23:58 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Christos Zoulas of Cornell University. 8 * Christos Zoulas of Cornell University.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include "config.h" 35#include "config.h"
36#if !defined(lint) && !defined(SCCSID) 36#if !defined(lint) && !defined(SCCSID)
37#if 0 37#if 0
38static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93"; 38static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93";
39#else 39#else
40__RCSID("$NetBSD: hist.c,v 1.31 2017/03/05 17:30:38 christos Exp $"); 40__RCSID("$NetBSD: hist.c,v 1.32 2017/03/05 19:23:58 christos Exp $");
41#endif 41#endif
42#endif /* not lint && not SCCSID */ 42#endif /* not lint && not SCCSID */
43 43
44/* 44/*
45 * hist.c: History access functions 45 * hist.c: History access functions
46 */ 46 */
47#include <stdlib.h> 47#include <stdlib.h>
48#include <string.h> 48#include <string.h>
49#include <vis.h> 49#include <vis.h>
50 50
51#include "el.h" 51#include "el.h"
52 52
53/* hist_init(): 53/* hist_init():
@@ -121,27 +121,27 @@ hist_get(EditLine *el) @@ -121,27 +121,27 @@ hist_get(EditLine *el)
121 } 121 }
122 if (el->el_history.ref == NULL) 122 if (el->el_history.ref == NULL)
123 return CC_ERROR; 123 return CC_ERROR;
124 124
125 hp = HIST_FIRST(el); 125 hp = HIST_FIRST(el);
126 126
127 if (hp == NULL) 127 if (hp == NULL)
128 return CC_ERROR; 128 return CC_ERROR;
129 129
130 for (h = 1; h < el->el_history.eventno; h++) 130 for (h = 1; h < el->el_history.eventno; h++)
131 if ((hp = HIST_NEXT(el)) == NULL) 131 if ((hp = HIST_NEXT(el)) == NULL)
132 goto out; 132 goto out;
133 133
134 hlen = wcslen(hp); 134 hlen = wcslen(hp) + 1;
135 blen = (size_t)(el->el_line.limit - el->el_line.buffer); 135 blen = (size_t)(el->el_line.limit - el->el_line.buffer);
136 if (hlen > blen && !ch_enlargebufs(el, hlen)) 136 if (hlen > blen && !ch_enlargebufs(el, hlen))
137 goto out; 137 goto out;
138 138
139 memcpy(el->el_line.buffer, hp, hlen * sizeof(*hp)); 139 memcpy(el->el_line.buffer, hp, hlen * sizeof(*hp));
140 el->el_line.lastchar = el->el_line.buffer + hlen - 1; 140 el->el_line.lastchar = el->el_line.buffer + hlen - 1;
141 141
142 if (el->el_line.lastchar > el->el_line.buffer 142 if (el->el_line.lastchar > el->el_line.buffer
143 && el->el_line.lastchar[-1] == '\n') 143 && el->el_line.lastchar[-1] == '\n')
144 el->el_line.lastchar--; 144 el->el_line.lastchar--;
145 if (el->el_line.lastchar > el->el_line.buffer 145 if (el->el_line.lastchar > el->el_line.buffer
146 && el->el_line.lastchar[-1] == ' ') 146 && el->el_line.lastchar[-1] == ' ')
147 el->el_line.lastchar--; 147 el->el_line.lastchar--;