summaryrefslogtreecommitdiff
path: root/cmd-line-utils/libedit/readline.c
diff options
context:
space:
mode:
authorunknown <monty@mysql.com>2004-09-06 15:14:10 +0300
committerunknown <monty@mysql.com>2004-09-06 15:14:10 +0300
commit4ad51359c1b7b5ed854f1af8df06fd6912068d28 (patch)
treed9ef905036723648a1d354d0523ef8124e4dee76 /cmd-line-utils/libedit/readline.c
parentfa3bfbe45796edd85cce30e62ff1fcfb81df745c (diff)
parent9a63c8e0e468d7a64dcb7e23f4e5c344eebf635b (diff)
downloadmariadb-git-4ad51359c1b7b5ed854f1af8df06fd6912068d28.tar.gz
Merge with 4.1
(Includes merge of arena code in 4.1 and 5.0) BitKeeper/etc/ignore: auto-union BitKeeper/etc/logging_ok: auto-union VC++Files/sql/mysqld.dsp: Auto merged client/mysql.cc: Auto merged client/mysqltest.c: Auto merged include/my_global.h: Auto merged include/my_sys.h: Auto merged include/mysql.h: Auto merged include/mysql_com.h: Auto merged innobase/row/row0sel.c: Auto merged libmysql/client_settings.h: Auto merged libmysql/libmysql.c: Auto merged libmysqld/Makefile.am: Auto merged libmysqld/examples/Makefile.am: Auto merged libmysqld/lib_sql.cc: Auto merged myisam/mi_check.c: Auto merged myisam/myisamchk.c: Auto merged myisam/sort.c: Auto merged mysql-test/r/connect.result: Auto merged mysql-test/r/ctype_recoding.result: Auto merged mysql-test/r/ctype_ucs.result: Auto merged mysql-test/r/func_in.result: Auto merged mysql-test/r/func_like.result: Auto merged mysql-test/r/gis.result: Auto merged mysql-test/r/having.result: Auto merged mysql-test/r/heap.result: Auto merged mysql-test/r/join.result: Auto merged mysql-test/r/key.result: Auto merged mysql-test/r/lowercase_table.result: Auto merged mysql-test/r/ndb_autodiscover.result: Auto merged mysql-test/r/null.result: Auto merged mysql-test/r/olap.result: Auto merged mysql-test/r/order_by.result: Auto merged mysql-test/r/ps_1general.result: Auto merged mysql-test/r/ps_2myisam.result: Auto merged mysql-test/r/ps_3innodb.result: Auto merged mysql-test/r/ps_4heap.result: Auto merged mysql-test/r/ps_5merge.result: Auto merged mysql-test/r/ps_6bdb.result: Auto merged mysql-test/r/range.result: Auto merged mysql-test/r/rename.result: Auto merged mysql-test/r/show_check.result: Auto merged mysql-test/r/subselect.result: Auto merged mysql-test/r/union.result: Auto merged mysql-test/r/variables.result: Auto merged mysql-test/t/alter_table.test: Auto merged mysql-test/t/null.test: Auto merged mysql-test/t/ps_1general.test: Auto merged mysql-test/t/rpl_charset.test: Auto merged mysql-test/t/rpl_heap.test: Auto merged mysql-test/t/rpl_relayrotate.test: Auto merged mysql-test/t/subselect.test: Auto merged mysql-test/t/variables.test: Auto merged netware/mysql_test_run.c: Auto merged scripts/make_binary_distribution.sh: Auto merged scripts/mysql_create_system_tables.sh: Auto merged scripts/mysql_fix_privilege_tables.sql: Auto merged scripts/mysql_install_db.sh: Auto merged sql/ha_berkeley.cc: Auto merged sql/ha_innodb.cc: Auto merged sql/ha_innodb.h: Auto merged sql/ha_myisam.cc: Auto merged sql/handler.cc: Auto merged sql/handler.h: Auto merged sql/item.h: Auto merged sql/item_cmpfunc.h: Auto merged sql/item_create.cc: Auto merged sql/item_create.h: Auto merged sql/item_func.cc: Auto merged sql/item_func.h: Auto merged sql/item_timefunc.cc: Auto merged sql/item_timefunc.h: Auto merged sql/lex.h: Auto merged sql/lock.cc: Auto merged sql/log_event.cc: Auto merged sql/mysql_priv.h: Auto merged sql/opt_sum.cc: Auto merged sql/protocol.cc: Auto merged sql/records.cc: Auto merged sql/repl_failsafe.cc: Auto merged sql/set_var.cc: Auto merged sql/set_var.h: Auto merged sql/slave.cc: Auto merged sql/sql_acl.cc: Auto merged sql/sql_acl.h: Auto merged sql/sql_db.cc: Auto merged sql/sql_delete.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_list.h: Auto merged sql/sql_load.cc: Auto merged sql/sql_rename.cc: Auto merged sql/sql_select.h: Auto merged sql/sql_show.cc: Auto merged sql/sql_string.h: Auto merged sql/table.cc: Auto merged sql-common/client.c: Auto merged client/mysqlbinlog.cc: Merge with 4.1 configure.in: Merge with 4.1 include/mysqld_error.h: Add new error message (1) from 4.1 mysql-test/mysql-test-run.sh: Merge with 4.1 mysql-test/r/func_gconcat.result: Merge with 4.1 mysql-test/r/func_if.result: Merge with 4.1 mysql-test/r/grant.result: Merge with 4.1 mysql-test/r/join_outer.result: Merge with 4.1 mysql-test/r/rpl_charset.result: Merge with 4.1 (This has to be fixed before pushing) mysql-test/r/system_mysql_db.result: Merge with 4.1. Added collation to new privileges mysql-test/t/grant.test: Merge with 4.1 mysql-test/t/grant_cache.test: Merge with 4.1 mysql-test/t/show_check.test: Merge with 4.1 sql/Makefile.am: Merge with 4.1 sql/item.cc: Merge with 4.1 sql/item_cmpfunc.cc: Merge with 4.1 (arena code) sql/item_subselect.cc: Merge with 4.1 sql/item_subselect.h: Merge with 4.1 sql/item_sum.cc: Merge with 4.1 sql/item_sum.h: Merge with 4.1 sql/log.cc: Merge with 4.1 (Remove code that is not relevant for 5.0) sql/mysqld.cc: Merge with 4.1 sql/opt_range.cc: Merge with 4.1 sql/share/czech/errmsg.txt: Merge with 4.1 sql/share/danish/errmsg.txt: Merge with 4.1 sql/share/dutch/errmsg.txt: Merge with 4.1 sql/share/english/errmsg.txt: Merge with 4.1 sql/share/estonian/errmsg.txt: Merge with 4.1 sql/share/french/errmsg.txt: Merge with 4.1 sql/share/german/errmsg.txt: Merge with 4.1 sql/share/greek/errmsg.txt: Merge with 4.1 sql/share/hungarian/errmsg.txt: Merge with 4.1 sql/share/italian/errmsg.txt: Merge with 4.1 sql/share/japanese/errmsg.txt: Merge with 4.1 sql/share/korean/errmsg.txt: Merge with 4.1 sql/share/norwegian-ny/errmsg.txt: Merge with 4.1 sql/share/norwegian/errmsg.txt: Merge with 4.1 sql/share/polish/errmsg.txt: Merge with 4.1 sql/share/portuguese/errmsg.txt: Merge with 4.1 sql/share/romanian/errmsg.txt: Merge with 4.1 sql/share/russian/errmsg.txt: Merge with 4.1 sql/share/serbian/errmsg.txt: Merge with 4.1 sql/share/slovak/errmsg.txt: Merge with 4.1 sql/share/spanish/errmsg.txt: Merge with 4.1 sql/share/swedish/errmsg.txt: Merge with 4.1 sql/share/ukrainian/errmsg.txt: Merge with 4.1 sql/sql_base.cc: Merge with 4.1 sql/sql_class.cc: Merge with 4.1 Use arena code from 4.1 sql/sql_class.h: Merge with 4.1 Use arena code from 4.1 sql/sql_derived.cc: Merge with 4.1 sql/sql_lex.cc: Merge with 4.1 sql/sql_lex.h: Merge with 4.1 sql/sql_parse.cc: Merge with 4.1 sql/sql_prepare.cc: Merge with 4.1 sql/sql_select.cc: Merge with 4.1 sql/sql_table.cc: Merge with 4.1 sql/sql_union.cc: Merge with 4.1 sql/sql_yacc.yy: Merge with 4.1 sql/tztime.cc: Merge with 4.1 tests/client_test.c: Merge with 4.1
Diffstat (limited to 'cmd-line-utils/libedit/readline.c')
-rw-r--r--cmd-line-utils/libedit/readline.c240
1 files changed, 179 insertions, 61 deletions
diff --git a/cmd-line-utils/libedit/readline.c b/cmd-line-utils/libedit/readline.c
index 9069b46d1f8..5b40ade582c 100644
--- a/cmd-line-utils/libedit/readline.c
+++ b/cmd-line-utils/libedit/readline.c
@@ -1,4 +1,4 @@
-/* $NetBSD: readline.c,v 1.19 2001/01/10 08:10:45 jdolecek Exp $ */
+/* $NetBSD: readline.c,v 1.28 2003/03/10 01:14:54 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -36,7 +36,11 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include "compat.h"
+#include "config.h"
+#if !defined(lint) && !defined(SCCSID)
+__RCSID("$NetBSD: readline.c,v 1.28 2003/03/10 01:14:54 christos Exp $");
+#endif /* not lint && not SCCSID */
+
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
@@ -47,14 +51,13 @@
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
+#ifdef HAVE_ALLOCA_H
+#include <alloca.h>
+#endif
#include "histedit.h"
#include "readline/readline.h"
-#include "sys.h"
#include "el.h"
#include "fcns.h" /* for EL_NUM_FCNS */
-#ifdef HAVE_ALLOCA_H
-#include <alloca.h>
-#endif
/* for rl_complete() */
#define TAB '\r'
@@ -65,7 +68,11 @@
/* readline compatibility stuff - look at readline sources/documentation */
/* to see what these variables mean */
const char *rl_library_version = "EditLine wrapper";
-const char *rl_readline_name = "";
+static char empty[] = { '\0' };
+static char expand_chars[] = { ' ', '\t', '\n', '=', '(', '\0' };
+static char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@', '$',
+ '>', '<', '=', ';', '|', '&', '{', '(', '\0' };
+char *rl_readline_name = empty;
FILE *rl_instream = NULL;
FILE *rl_outstream = NULL;
int rl_point = 0;
@@ -77,12 +84,12 @@ int history_length = 0;
int max_input_history = 0;
char history_expansion_char = '!';
char history_subst_char = '^';
-const char *history_no_expand_chars = " \t\n=(";
+char *history_no_expand_chars = expand_chars;
Function *history_inhibit_expansion_function = NULL;
int rl_inhibit_completion = 0;
int rl_attempted_completion_over = 0;
-const char *rl_basic_word_break_characters = " \t\n\"\\'`@$><=;|&{(";
+char *rl_basic_word_break_characters = break_chars;
char *rl_completer_word_break_characters = NULL;
char *rl_completer_quote_characters = NULL;
CPFunction *rl_completion_entry_function = NULL;
@@ -215,6 +222,11 @@ rl_initialize(void)
/* for proper prompt printing in readline() */
el_rl_prompt = strdup("");
+ if (el_rl_prompt == NULL) {
+ history_end(h);
+ el_end(e);
+ return -1;
+ }
el_set(e, EL_PROMPT, _get_prompt);
el_set(e, EL_SIGNAL, 1);
@@ -250,8 +262,8 @@ rl_initialize(void)
* and rl_line_buffer directly.
*/
li = el_line(e);
- /* LINTED const cast */
- rl_line_buffer = (char *) li->buffer;
+ /* a cheesy way to get rid of const cast. */
+ rl_line_buffer = memchr(li->buffer, *li->buffer, 1);
rl_point = rl_end = 0;
return (0);
@@ -268,6 +280,7 @@ readline(const char *prompt)
HistEvent ev;
int count;
const char *ret;
+ char *buf;
if (e == NULL || h == NULL)
rl_initialize();
@@ -278,28 +291,28 @@ readline(const char *prompt)
if (strcmp(el_rl_prompt, prompt) != 0) {
free(el_rl_prompt);
el_rl_prompt = strdup(prompt);
+ if (el_rl_prompt == NULL)
+ return NULL;
}
/* get one line from input stream */
ret = el_gets(e, &count);
if (ret && count > 0) {
- char *foo;
int lastidx;
- foo = strdup(ret);
+ buf = strdup(ret);
+ if (buf == NULL)
+ return NULL;
lastidx = count - 1;
- if (foo[lastidx] == '\n')
- foo[lastidx] = '\0';
-
- ret = foo;
+ if (buf[lastidx] == '\n')
+ buf[lastidx] = '\0';
} else
- ret = NULL;
+ buf = NULL;
history(h, &ev, H_GETSIZE);
history_length = ev.num;
- /* LINTED const cast */
- return (char *) ret;
+ return buf;
}
/*
@@ -333,6 +346,8 @@ _rl_compat_sub(const char *str, const char *what, const char *with,
size_t size, i;
result = malloc((size = 16));
+ if (result == NULL)
+ return NULL;
temp = str;
with_len = strlen(with);
what_len = strlen(what);
@@ -343,8 +358,14 @@ _rl_compat_sub(const char *str, const char *what, const char *with,
i = new - temp;
add = i + with_len;
if (i + add + 1 >= size) {
+ char *nresult;
size += add + 1;
- result = realloc(result, size);
+ nresult = realloc(result, size);
+ if (nresult == NULL) {
+ free(result);
+ return NULL;
+ }
+ result = nresult;
}
(void) strncpy(&result[len], temp, i);
len += i;
@@ -354,8 +375,14 @@ _rl_compat_sub(const char *str, const char *what, const char *with,
} else {
add = strlen(temp);
if (len + add + 1 >= size) {
+ char *nresult;
size += add + 1;
- result = realloc(result, size);
+ nresult = realloc(result, size);
+ if (nresult == NULL) {
+ free(result);
+ return NULL;
+ }
+ result = nresult;
}
(void) strcpy(&result[len], temp); /* safe */
len += add;
@@ -392,7 +419,7 @@ _history_expand_command(const char *command, size_t cmdlen, char **result)
*result = NULL;
- cmd = (char*) alloca(cmdlen + 1);
+ cmd = alloca(cmdlen + 1);
(void) strncpy(cmd, command, cmdlen);
cmd[cmdlen] = 0;
@@ -425,7 +452,7 @@ _history_expand_command(const char *command, size_t cmdlen, char **result)
return (-1);
prefix = 0;
}
- search = (char*) alloca(len + 1);
+ search = alloca(len + 1);
(void) strncpy(search, &cmd[idx], len);
search[len] = '\0';
@@ -498,6 +525,8 @@ _history_expand_command(const char *command, size_t cmdlen, char **result)
cmd++;
line = strdup(event_data);
+ if (line == NULL)
+ return 0;
for (; *cmd; cmd++) {
if (*cmd == ':')
continue;
@@ -515,7 +544,7 @@ _history_expand_command(const char *command, size_t cmdlen, char **result)
g_on = 2;
else if (*cmd == 's' || *cmd == '&') {
char *what, *with, delim;
- size_t len, from_len;
+ unsigned int len, from_len;
size_t size;
if (*cmd == '&' && (from == NULL || to == NULL))
@@ -524,23 +553,36 @@ _history_expand_command(const char *command, size_t cmdlen, char **result)
delim = *(++cmd), cmd++;
size = 16;
what = realloc(from, size);
+ if (what == NULL) {
+ free(from);
+ return 0;
+ }
len = 0;
for (; *cmd && *cmd != delim; cmd++) {
if (*cmd == '\\'
&& *(cmd + 1) == delim)
cmd++;
- if (len >= size)
- what = realloc(what,
+ if (len >= size) {
+ char *nwhat;
+ nwhat = realloc(what,
(size <<= 1));
+ if (nwhat == NULL) {
+ free(what);
+ return 0;
+ }
+ what = nwhat;
+ }
what[len++] = *cmd;
}
what[len] = '\0';
from = what;
if (*what == '\0') {
free(what);
- if (search)
+ if (search) {
from = strdup(search);
- else {
+ if (from == NULL)
+ return 0;
+ } else {
from = NULL;
return (-1);
}
@@ -551,12 +593,22 @@ _history_expand_command(const char *command, size_t cmdlen, char **result)
size = 16;
with = realloc(to, size);
+ if (with == NULL) {
+ free(to);
+ return -1;
+ }
len = 0;
from_len = strlen(from);
for (; *cmd && *cmd != delim; cmd++) {
if (len + from_len + 1 >= size) {
+ char *nwith;
size += from_len + 1;
- with = realloc(with, size);
+ nwith = realloc(with, size);
+ if (nwith == NULL) {
+ free(with);
+ return -1;
+ }
+ with = nwith;
}
if (*cmd == '&') {
/* safe */
@@ -575,8 +627,10 @@ _history_expand_command(const char *command, size_t cmdlen, char **result)
tempcmd = _rl_compat_sub(line, from, to,
(g_on) ? 1 : 0);
- free(line);
- line = tempcmd;
+ if (tempcmd) {
+ free(line);
+ line = tempcmd;
+ }
g_on = 0;
}
}
@@ -622,14 +676,21 @@ _history_expand_command(const char *command, size_t cmdlen, char **result)
}
cmdsize = 1, cmdlen = 0;
- tempcmd = malloc(cmdsize);
+ if ((tempcmd = malloc(cmdsize)) == NULL)
+ return 0;
for (i = start; start <= i && i <= end; i++) {
int arr_len;
arr_len = strlen(arr[i]);
if (cmdlen + arr_len + 1 >= cmdsize) {
+ char *ntempcmd;
cmdsize += arr_len + 1;
- tempcmd = realloc(tempcmd, cmdsize);
+ ntempcmd = realloc(tempcmd, cmdsize);
+ if (ntempcmd == NULL) {
+ free(tempcmd);
+ return 0;
+ }
+ tempcmd = ntempcmd;
}
(void) strcpy(&tempcmd[cmdlen], arr[i]); /* safe */
cmdlen += arr_len;
@@ -662,10 +723,12 @@ history_expand(char *str, char **output)
rl_initialize();
*output = strdup(str); /* do it early */
+ if (*output == NULL)
+ return 0;
if (str[0] == history_subst_char) {
/* ^foo^foo2^ is equivalent to !!:s^foo^foo2^ */
- temp = (char*) alloca(4 + strlen(str) + 1);
+ temp = alloca(4 + strlen(str) + 1);
temp[0] = temp[1] = history_expansion_char;
temp[2] = ':';
temp[3] = 's';
@@ -674,8 +737,14 @@ history_expand(char *str, char **output)
}
#define ADD_STRING(what, len) \
{ \
- if (idx + len + 1 > size) \
- result = realloc(result, (size += len + 1)); \
+ if (idx + len + 1 > size) { \
+ char *nresult = realloc(result, (size += len + 1));\
+ if (nresult == NULL) { \
+ free(*output); \
+ return 0; \
+ } \
+ result = nresult; \
+ } \
(void)strncpy(&result[idx], what, len); \
idx += len; \
result[idx] = '\0'; \
@@ -789,11 +858,21 @@ history_tokenize(const char *str)
}
if (result_idx + 2 >= size) {
+ char **nresult;
size <<= 1;
- result = realloc(result, size * sizeof(char *));
+ nresult = realloc(result, size * sizeof(char *));
+ if (nresult == NULL) {
+ free(result);
+ return NULL;
+ }
+ result = nresult;
}
len = i - start;
temp = malloc(len + 1);
+ if (temp == NULL) {
+ free(result);
+ return NULL;
+ }
(void) strncpy(temp, &str[start], len);
temp[len] = '\0';
result[result_idx++] = temp;
@@ -1158,11 +1237,15 @@ tilde_expand(char *txt)
return (strdup(txt));
temp = strchr(txt + 1, '/');
- if (temp == NULL)
+ if (temp == NULL) {
temp = strdup(txt + 1);
- else {
+ if (temp == NULL)
+ return NULL;
+ } else {
len = temp - txt + 1; /* text until string after slash */
temp = malloc(len);
+ if (temp == NULL)
+ return NULL;
(void) strncpy(temp, txt + 1, len - 2);
temp[len - 2] = '\0';
}
@@ -1176,6 +1259,8 @@ tilde_expand(char *txt)
txt += len;
temp = malloc(strlen(pass->pw_dir) + 1 + strlen(txt) + 1);
+ if (temp == NULL)
+ return NULL;
(void) sprintf(temp, "%s/%s", pass->pw_dir, txt);
return (temp);
@@ -1200,28 +1285,45 @@ filename_completion_function(const char *text, int state)
size_t len;
if (state == 0 || dir == NULL) {
- if (dir != NULL) {
- closedir(dir);
- dir = NULL;
- }
temp = strrchr(text, '/');
if (temp) {
+ char *nptr;
temp++;
- filename = realloc(filename, strlen(temp) + 1);
+ nptr = realloc(filename, strlen(temp) + 1);
+ if (nptr == NULL) {
+ free(filename);
+ return NULL;
+ }
+ filename = nptr;
(void) strcpy(filename, temp);
len = temp - text; /* including last slash */
- dirname = realloc(dirname, len + 1);
+ nptr = realloc(dirname, len + 1);
+ if (nptr == NULL) {
+ free(filename);
+ return NULL;
+ }
+ dirname = nptr;
(void) strncpy(dirname, text, len);
dirname[len] = '\0';
} else {
filename = strdup(text);
+ if (filename == NULL)
+ return NULL;
dirname = NULL;
}
/* support for ``~user'' syntax */
if (dirname && *dirname == '~') {
+ char *nptr;
temp = tilde_expand(dirname);
- dirname = realloc(dirname, strlen(temp) + 1);
+ if (temp == NULL)
+ return NULL;
+ nptr = realloc(dirname, strlen(temp) + 1);
+ if (nptr == NULL) {
+ free(dirname);
+ return NULL;
+ }
+ dirname = nptr;
(void) strcpy(dirname, temp); /* safe */
free(temp); /* no longer needed */
}
@@ -1230,6 +1332,10 @@ filename_completion_function(const char *text, int state)
if (filename_len == 0)
return (NULL); /* no expansion possible */
+ if (dir != NULL) {
+ (void)closedir(dir);
+ dir = NULL;
+ }
dir = opendir(dirname ? dirname : ".");
if (!dir)
return (NULL); /* cannot open the directory */
@@ -1239,7 +1345,7 @@ filename_completion_function(const char *text, int state)
/* otherwise, get first entry where first */
/* filename_len characters are equal */
if (entry->d_name[0] == filename[0]
-#ifdef HAVE_DIRENT_H
+#ifndef STRUCT_DIRENT_HAS_D_NAMLEN
&& strlen(entry->d_name) >= filename_len
#else
&& entry->d_namlen >= filename_len
@@ -1252,21 +1358,26 @@ filename_completion_function(const char *text, int state)
if (entry) { /* match found */
struct stat stbuf;
-#ifdef HAVE_DIRENT_H
+#ifndef STRUCT_DIRENT_HAS_D_NAMLEN
len = strlen(entry->d_name) +
#else
len = entry->d_namlen +
#endif
((dirname) ? strlen(dirname) : 0) + 1 + 1;
temp = malloc(len);
+ if (temp == NULL)
+ return NULL;
(void) sprintf(temp, "%s%s",
dirname ? dirname : "", entry->d_name); /* safe */
/* test, if it's directory */
if (stat(temp, &stbuf) == 0 && S_ISDIR(stbuf.st_mode))
strcat(temp, "/"); /* safe */
- } else
+ } else {
+ (void)closedir(dir);
+ dir = NULL;
temp = NULL;
+ }
return (temp);
}
@@ -1331,16 +1442,24 @@ completion_matches(const char *text, CPFunction *genfunc)
matches = 0;
match_list_len = 1;
while ((retstr = (*genfunc) (text, matches)) != NULL) {
- if (matches + 1 >= match_list_len) {
+ /* allow for list terminator here */
+ if (matches + 2 >= match_list_len) {
+ char **nmatch_list;
match_list_len <<= 1;
- match_list = realloc(match_list,
+ nmatch_list = realloc(match_list,
match_list_len * sizeof(char *));
+ if (nmatch_list == NULL) {
+ free(match_list);
+ return NULL;
+ }
+ match_list = nmatch_list;
+
}
match_list[++matches] = retstr;
}
if (!match_list)
- return (char **) NULL; /* nothing found */
+ return NULL; /* nothing found */
/* find least denominator and insert it to match_list[0] */
which = 2;
@@ -1354,14 +1473,15 @@ completion_matches(const char *text, CPFunction *genfunc)
}
retstr = malloc(max_equal + 1);
+ if (retstr == NULL) {
+ free(match_list);
+ return NULL;
+ }
(void) strncpy(retstr, match_list[1], max_equal);
retstr[max_equal] = '\0';
match_list[0] = retstr;
/* add NULL as last pointer to the array */
- if (matches + 1 >= match_list_len)
- match_list = realloc(match_list,
- (match_list_len + 1) * sizeof(char *));
match_list[matches + 1] = (char *) NULL;
return (match_list);
@@ -1374,10 +1494,8 @@ static int
_rl_qsort_string_compare(i1, i2)
const void *i1, *i2;
{
- /*LINTED const castaway*/
- const char *s1 = ((const char **)i1)[0];
- /*LINTED const castaway*/
- const char *s2 = ((const char **)i2)[0];
+ const char *s1 = ((const char * const *)i1)[0];
+ const char *s2 = ((const char * const *)i2)[0];
return strcasecmp(s1, s2);
}
@@ -1459,7 +1577,7 @@ rl_complete_internal(int what_to_do)
ctemp--;
len = li->cursor - ctemp;
- temp = (char*) alloca(len + 1);
+ temp = alloca(len + 1);
(void) strncpy(temp, ctemp, len);
temp[len] = '\0';