Wed Apr 8 21:31:31 2009 UTC ()
Fix off by one error reported by:  Caleb Welton cwelton at greenplum dot com


(christos)
diff -r1.82 -r1.83 src/lib/libedit/readline.c

cvs diff -r1.82 -r1.83 src/lib/libedit/readline.c (expand / switch to unified diff)

--- src/lib/libedit/readline.c 2009/03/31 17:53:03 1.82
+++ src/lib/libedit/readline.c 2009/04/08 21:31:31 1.83
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: readline.c,v 1.82 2009/03/31 17:53:03 christos Exp $ */ 1/* $NetBSD: readline.c,v 1.83 2009/04/08 21:31:31 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jaromir Dolecek. 8 * by Jaromir Dolecek.
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.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include "config.h" 32#include "config.h"
33#if !defined(lint) && !defined(SCCSID) 33#if !defined(lint) && !defined(SCCSID)
34__RCSID("$NetBSD: readline.c,v 1.82 2009/03/31 17:53:03 christos Exp $"); 34__RCSID("$NetBSD: readline.c,v 1.83 2009/04/08 21:31:31 christos Exp $");
35#endif /* not lint && not SCCSID */ 35#endif /* not lint && not SCCSID */
36 36
37#include <sys/types.h> 37#include <sys/types.h>
38#include <sys/stat.h> 38#include <sys/stat.h>
39#include <stdio.h> 39#include <stdio.h>
40#include <dirent.h> 40#include <dirent.h>
41#include <string.h> 41#include <string.h>
42#include <pwd.h> 42#include <pwd.h>
43#include <ctype.h> 43#include <ctype.h>
44#include <stdlib.h> 44#include <stdlib.h>
45#include <unistd.h> 45#include <unistd.h>
46#include <limits.h> 46#include <limits.h>
47#include <errno.h> 47#include <errno.h>
@@ -1854,34 +1854,34 @@ rl_set_screen_size(int rows, int cols) @@ -1854,34 +1854,34 @@ rl_set_screen_size(int rows, int cols)
1854 1854
1855char ** 1855char **
1856rl_completion_matches(const char *str, rl_compentry_func_t *fun) 1856rl_completion_matches(const char *str, rl_compentry_func_t *fun)
1857{ 1857{
1858 size_t len, max, i, j, min; 1858 size_t len, max, i, j, min;
1859 char **list, *match, *a, *b; 1859 char **list, *match, *a, *b;
1860 1860
1861 len = 1; 1861 len = 1;
1862 max = 10; 1862 max = 10;
1863 if ((list = malloc(max * sizeof(*list))) == NULL) 1863 if ((list = malloc(max * sizeof(*list))) == NULL)
1864 return NULL; 1864 return NULL;
1865 1865
1866 while ((match = (*fun)(str, (int)(len - 1))) != NULL) { 1866 while ((match = (*fun)(str, (int)(len - 1))) != NULL) {
 1867 list[len++] = match;
1867 if (len == max) { 1868 if (len == max) {
1868 char **nl; 1869 char **nl;
1869 max += 10; 1870 max += 10;
1870 if ((nl = realloc(list, max * sizeof(*nl))) == NULL) 1871 if ((nl = realloc(list, max * sizeof(*nl))) == NULL)
1871 goto out; 1872 goto out;
1872 list = nl; 1873 list = nl;
1873 } 1874 }
1874 list[len++] = match; 
1875 } 1875 }
1876 if (len == 1) 1876 if (len == 1)
1877 goto out; 1877 goto out;
1878 list[len] = NULL; 1878 list[len] = NULL;
1879 if (len == 2) { 1879 if (len == 2) {
1880 if ((list[0] = strdup(list[1])) == NULL) 1880 if ((list[0] = strdup(list[1])) == NULL)
1881 goto out; 1881 goto out;
1882 return list; 1882 return list;
1883 } 1883 }
1884 qsort(&list[1], len - 1, sizeof(*list), 1884 qsort(&list[1], len - 1, sizeof(*list),
1885 (int (*)(const void *, const void *)) strcmp); 1885 (int (*)(const void *, const void *)) strcmp);
1886 min = SIZE_T_MAX; 1886 min = SIZE_T_MAX;
1887 for (i = 1, a = list[i]; i < len - 1; i++, a = b) { 1887 for (i = 1, a = list[i]; i < len - 1; i++, a = b) {