summaryrefslogtreecommitdiff
path: root/lib/libedit
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2001-01-04 15:56:31 +0000
committerchristos <christos@NetBSD.org>2001-01-04 15:56:31 +0000
commit2f3389ce5e3b5a9efa2b5a826fdfda47cba885b2 (patch)
tree1f0dd9f7624e0191d20e6a8bb15eab5ea78abaa8 /lib/libedit
parentab7e5eaeb3267e41ca10ec8794f53609dae55da5 (diff)
consistently check for allocation failures and return -1, if we could not
get more memory.
Diffstat (limited to 'lib/libedit')
-rw-r--r--lib/libedit/chared.c19
-rw-r--r--lib/libedit/hist.c6
-rw-r--r--lib/libedit/key.c8
-rw-r--r--lib/libedit/map.c26
-rw-r--r--lib/libedit/search.c6
-rw-r--r--lib/libedit/term.c62
-rw-r--r--lib/libedit/term.h4
-rw-r--r--lib/libedit/tokenizer.c16
8 files changed, 108 insertions, 39 deletions
diff --git a/lib/libedit/chared.c b/lib/libedit/chared.c
index a4d0768000d..7e90637c18a 100644
--- a/lib/libedit/chared.c
+++ b/lib/libedit/chared.c
@@ -1,4 +1,4 @@
-/* $NetBSD: chared.c,v 1.10 2000/11/11 22:18:57 christos Exp $ */
+/* $NetBSD: chared.c,v 1.11 2001/01/04 15:56:31 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: chared.c,v 1.10 2000/11/11 22:18:57 christos Exp $");
+__RCSID("$NetBSD: chared.c,v 1.11 2001/01/04 15:56:31 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -403,13 +403,18 @@ cv__endword(char *p, char *high, int n)
protected int
ch_init(EditLine *el)
{
- el->el_line.buffer = (char *) el_malloc(EL_BUFSIZ);
+ el->el_line.buffer = (char *) el_malloc(EL_BUFSIZ);
+ if (el->el_line.buffer == NULL)
+ return (-1);
+
(void) memset(el->el_line.buffer, 0, EL_BUFSIZ);
el->el_line.cursor = el->el_line.buffer;
el->el_line.lastchar = el->el_line.buffer;
el->el_line.limit = &el->el_line.buffer[EL_BUFSIZ - 2];
- el->el_chared.c_undo.buf = (char *) el_malloc(EL_BUFSIZ);
+ el->el_chared.c_undo.buf = (char *) el_malloc(EL_BUFSIZ);
+ if (el->el_chared.c_undo.buf == NULL)
+ return (-1);
(void) memset(el->el_chared.c_undo.buf, 0, EL_BUFSIZ);
el->el_chared.c_undo.action = NOP;
el->el_chared.c_undo.isize = 0;
@@ -421,6 +426,8 @@ ch_init(EditLine *el)
el->el_chared.c_vcmd.ins = el->el_line.buffer;
el->el_chared.c_kill.buf = (char *) el_malloc(EL_BUFSIZ);
+ if (el->el_chared.c_kill.buf == NULL)
+ return (-1);
(void) memset(el->el_chared.c_kill.buf, 0, EL_BUFSIZ);
el->el_chared.c_kill.mark = el->el_line.buffer;
el->el_chared.c_kill.last = el->el_chared.c_kill.buf;
@@ -436,7 +443,9 @@ ch_init(EditLine *el)
el->el_chared.c_macro.nline = NULL;
el->el_chared.c_macro.level = -1;
el->el_chared.c_macro.macro = (char **) el_malloc(EL_MAXMACRO *
- sizeof(char *));
+ sizeof(char *));
+ if (el->el_chared.c_macro.macro == NULL)
+ return (-1);
return (0);
}
diff --git a/lib/libedit/hist.c b/lib/libedit/hist.c
index 1e427ad8922..0b956d84fd8 100644
--- a/lib/libedit/hist.c
+++ b/lib/libedit/hist.c
@@ -1,4 +1,4 @@
-/* $NetBSD: hist.c,v 1.6 2000/09/04 22:06:29 lukem Exp $ */
+/* $NetBSD: hist.c,v 1.7 2001/01/04 15:56:31 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: hist.c,v 1.6 2000/09/04 22:06:29 lukem Exp $");
+__RCSID("$NetBSD: hist.c,v 1.7 2001/01/04 15:56:31 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -62,6 +62,8 @@ hist_init(EditLine *el)
el->el_history.fun = NULL;
el->el_history.ref = NULL;
el->el_history.buf = (char *) el_malloc(EL_BUFSIZ);
+ if (el->el_history.buf == NULL)
+ return (-1);
el->el_history.last = el->el_history.buf;
return (0);
}
diff --git a/lib/libedit/key.c b/lib/libedit/key.c
index 4f5a299639c..95800b069e6 100644
--- a/lib/libedit/key.c
+++ b/lib/libedit/key.c
@@ -1,4 +1,4 @@
-/* $NetBSD: key.c,v 1.9 2000/11/11 22:18:57 christos Exp $ */
+/* $NetBSD: key.c,v 1.10 2001/01/04 15:56:31 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)key.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: key.c,v 1.9 2000/11/11 22:18:57 christos Exp $");
+__RCSID("$NetBSD: key.c,v 1.10 2001/01/04 15:56:31 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -107,6 +107,8 @@ key_init(EditLine *el)
{
el->el_key.buf = (char *) el_malloc(KEY_BUFSIZ);
+ if (el->el_key.buf == NULL)
+ return (-1);
el->el_key.map = NULL;
key_reset(el);
return (0);
@@ -459,6 +461,8 @@ node__get(int ch)
key_node_t *ptr;
ptr = (key_node_t *) el_malloc((size_t) sizeof(key_node_t));
+ if (ptr == NULL)
+ return NULL;
ptr->ch = ch;
ptr->type = XK_NOD;
ptr->val.str = NULL;
diff --git a/lib/libedit/map.c b/lib/libedit/map.c
index ff0bf1f04cb..b683dbe9e34 100644
--- a/lib/libedit/map.c
+++ b/lib/libedit/map.c
@@ -1,4 +1,4 @@
-/* $NetBSD: map.c,v 1.12 2000/11/11 22:18:57 christos Exp $ */
+/* $NetBSD: map.c,v 1.13 2001/01/04 15:56:32 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: map.c,v 1.12 2000/11/11 22:18:57 christos Exp $");
+__RCSID("$NetBSD: map.c,v 1.13 2001/01/04 15:56:32 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -911,16 +911,24 @@ map_init(EditLine *el)
#endif
el->el_map.alt = (el_action_t *)el_malloc(sizeof(el_action_t) * N_KEYS);
+ if (el->el_map.alt == NULL)
+ return (-1);
el->el_map.key = (el_action_t *)el_malloc(sizeof(el_action_t) * N_KEYS);
+ if (el->el_map.key == NULL)
+ return (-1);
el->el_map.emacs = el_map_emacs;
el->el_map.vic = el_map_vi_command;
el->el_map.vii = el_map_vi_insert;
el->el_map.help = (el_bindings_t *) el_malloc(sizeof(el_bindings_t) *
EL_NUM_FCNS);
+ if (el->el_map.help == NULL)
+ return (-1);
(void) memcpy(el->el_map.help, help__get(),
sizeof(el_bindings_t) * EL_NUM_FCNS);
- el->el_map.func = (el_func_t *) el_malloc(sizeof(el_func_t) *
+ el->el_map.func = (el_func_t *)el_malloc(sizeof(el_func_t) *
EL_NUM_FCNS);
+ if (el->el_map.func == NULL)
+ return (-1);
memcpy(el->el_map.func, func__get(), sizeof(el_func_t) * EL_NUM_FCNS);
el->el_map.nfunc = EL_NUM_FCNS;
@@ -1384,15 +1392,19 @@ map_bind(EditLine *el, int argc, char **argv)
protected int
map_addfunc(EditLine *el, const char *name, const char *help, el_func_t func)
{
+ void *p;
int nf = el->el_map.nfunc + 2;
if (name == NULL || help == NULL || func == NULL)
return (-1);
- el->el_map.func = (el_func_t *)
- el_realloc(el->el_map.func, nf * sizeof(el_func_t));
- el->el_map.help = (el_bindings_t *)
- el_realloc(el->el_map.help, nf * sizeof(el_bindings_t));
+ if ((p = el_realloc(el->el_map.func, nf * sizeof(el_func_t))) == NULL)
+ return (-1);
+ el->el_map.func = (el_func_t *) p;
+ if ((p = el_realloc(el->el_map.help, nf * sizeof(el_bindings_t)))
+ == NULL)
+ return (-1);
+ el->el_map.help = (el_bindings_t *) p;
nf = el->el_map.nfunc;
el->el_map.func[nf] = func;
diff --git a/lib/libedit/search.c b/lib/libedit/search.c
index ef949bcb8a0..37ede680998 100644
--- a/lib/libedit/search.c
+++ b/lib/libedit/search.c
@@ -1,4 +1,4 @@
-/* $NetBSD: search.c,v 1.9 2000/09/04 22:06:32 lukem Exp $ */
+/* $NetBSD: search.c,v 1.10 2001/01/04 15:56:32 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: search.c,v 1.9 2000/09/04 22:06:32 lukem Exp $");
+__RCSID("$NetBSD: search.c,v 1.10 2001/01/04 15:56:32 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -72,6 +72,8 @@ search_init(EditLine *el)
{
el->el_search.patbuf = (char *) el_malloc(EL_BUFSIZ);
+ if (el->el_search.patbuf == NULL)
+ return (-1);
el->el_search.patlen = 0;
el->el_search.patdir = -1;
el->el_search.chacha = '\0';
diff --git a/lib/libedit/term.c b/lib/libedit/term.c
index 35df8153869..8668926b5ef 100644
--- a/lib/libedit/term.c
+++ b/lib/libedit/term.c
@@ -1,4 +1,4 @@
-/* $NetBSD: term.c,v 1.27 2000/12/30 22:46:05 jdolecek Exp $ */
+/* $NetBSD: term.c,v 1.28 2001/01/04 15:56:32 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95";
#else
-__RCSID("$NetBSD: term.c,v 1.27 2000/12/30 22:46:05 jdolecek Exp $");
+__RCSID("$NetBSD: term.c,v 1.28 2001/01/04 15:56:32 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -258,9 +258,9 @@ private struct termcapval {
/* do two or more of the attributes use me */
private void term_setflags(EditLine *);
-private void term_rebuffer_display(EditLine *);
+private int term_rebuffer_display(EditLine *);
private void term_free_display(EditLine *);
-private void term_alloc_display(EditLine *);
+private int term_alloc_display(EditLine *);
private void term_alloc(EditLine *, struct termcapstr *, char *);
private void term_init_arrow(EditLine *);
private void term_reset_arrow(EditLine *);
@@ -323,15 +323,26 @@ term_init(EditLine *el)
{
el->el_term.t_buf = (char *) el_malloc(TC_BUFSIZE);
+ if (el->el_term.t_buf == NULL)
+ return (-1);
el->el_term.t_cap = (char *) el_malloc(TC_BUFSIZE);
+ if (el->el_term.t_cap == NULL)
+ return (-1);
el->el_term.t_fkey = (fkey_t *) el_malloc(A_K_NKEYS * sizeof(fkey_t));
+ if (el->el_term.t_fkey == NULL)
+ return (-1);
el->el_term.t_loc = 0;
el->el_term.t_str = (char **) el_malloc(T_str * sizeof(char *));
+ if (el->el_term.t_str == NULL)
+ return (-1);
(void) memset(el->el_term.t_str, 0, T_str * sizeof(char *));
el->el_term.t_val = (int *) el_malloc(T_val * sizeof(int));
+ if (el->el_term.t_val == NULL)
+ return (-1);
(void) memset(el->el_term.t_val, 0, T_val * sizeof(int));
term_outfile = el->el_outfile;
- (void) term_set(el, NULL);
+ if (term_set(el, NULL) == -1)
+ return (-1);
term_init_arrow(el);
return (0);
}
@@ -421,7 +432,7 @@ term_alloc(EditLine *el, struct termcapstr *t, char *cap)
/* term_rebuffer_display():
* Rebuffer the display after the screen changed size
*/
-private void
+private int
term_rebuffer_display(EditLine *el)
{
coord_t *c = &el->el_term.t_size;
@@ -431,14 +442,16 @@ term_rebuffer_display(EditLine *el)
c->h = Val(T_co);
c->v = (EL_BUFSIZ * 4) / c->h + 1;
- term_alloc_display(el);
+ if (term_alloc_display(el) == -1)
+ return (-1);
+ return (0);
}
/* term_alloc_display():
* Allocate a new display.
*/
-private void
+private int
term_alloc_display(EditLine *el)
{
int i;
@@ -446,17 +459,27 @@ term_alloc_display(EditLine *el)
coord_t *c = &el->el_term.t_size;
b = (char **) el_malloc((size_t) (sizeof(char *) * (c->v + 1)));
- for (i = 0; i < c->v; i++)
+ if (b == NULL)
+ return (-1);
+ for (i = 0; i < c->v; i++) {
b[i] = (char *) el_malloc((size_t) (sizeof(char) * (c->h + 1)));
+ if (b[i] == NULL)
+ return (-1);
+ }
b[c->v] = NULL;
el->el_display = b;
b = (char **) el_malloc((size_t) (sizeof(char *) * (c->v + 1)));
- for (i = 0; i < c->v; i++)
+ if (b == NULL)
+ return (-1);
+ for (i = 0; i < c->v; i++) {
b[i] = (char *) el_malloc((size_t) (sizeof(char) * (c->h + 1)));
+ if (b[i] == NULL)
+ return (-1);
+ }
b[c->v] = NULL;
el->el_vdisplay = b;
-
+ return (0);
}
@@ -927,7 +950,8 @@ term_set(EditLine *el, char *term)
/* get the correct window size */
(void) term_get_size(el, &lins, &cols);
- term_change_size(el, lins, cols);
+ if (term_change_size(el, lins, cols) == -1)
+ return (-1);
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
term_bind_arrow(el);
return (i <= 0 ? -1 : 0);
@@ -974,7 +998,7 @@ term_get_size(EditLine *el, int *lins, int *cols)
/* term_change_size():
* Change the size of the terminal
*/
-protected void
+protected int
term_change_size(EditLine *el, int lins, int cols)
{
/*
@@ -983,8 +1007,11 @@ term_change_size(EditLine *el, int lins, int cols)
Val(T_co) = (cols < 2) ? 80 : cols;
Val(T_li) = (lins < 1) ? 24 : lins;
- term_rebuffer_display(el); /* re-make display buffers */
+ /* re-make display buffers */
+ if (term_rebuffer_display(el) == -1)
+ return (-1);
re_clear_display(el);
+ return (0);
}
@@ -1294,7 +1321,8 @@ term_settc(EditLine *el, int argc, char **argv)
return (-1);
}
term_setflags(el);
- term_change_size(el, Val(T_li), Val(T_co));
+ if (term_change_size(el, Val(T_li), Val(T_co)) == -1)
+ return (-1);
return (0);
} else {
long i;
@@ -1310,7 +1338,9 @@ term_settc(EditLine *el, int argc, char **argv)
el->el_term.t_size.v = Val(T_co);
el->el_term.t_size.h = Val(T_li);
if (tv == &tval[T_co] || tv == &tval[T_li])
- term_change_size(el, Val(T_li), Val(T_co));
+ if (term_change_size(el, Val(T_li), Val(T_co))
+ == -1)
+ return (-1);
return (0);
}
}
diff --git a/lib/libedit/term.h b/lib/libedit/term.h
index 21296f1d1dd..57b233262fd 100644
--- a/lib/libedit/term.h
+++ b/lib/libedit/term.h
@@ -1,4 +1,4 @@
-/* $NetBSD: term.h,v 1.11 2000/11/11 22:18:58 christos Exp $ */
+/* $NetBSD: term.h,v 1.12 2001/01/04 15:56:32 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -92,7 +92,7 @@ protected void term_insertwrite(EditLine *, char *, int);
protected void term_deletechars(EditLine *, int);
protected void term_clear_screen(EditLine *);
protected void term_beep(EditLine *);
-protected void term_change_size(EditLine *, int, int);
+protected int term_change_size(EditLine *, int, int);
protected int term_get_size(EditLine *, int *, int *);
protected int term_init(EditLine *);
protected void term_bind_arrow(EditLine *);
diff --git a/lib/libedit/tokenizer.c b/lib/libedit/tokenizer.c
index cc87f2de10e..ed9f3652fa4 100644
--- a/lib/libedit/tokenizer.c
+++ b/lib/libedit/tokenizer.c
@@ -1,4 +1,4 @@
-/* $NetBSD: tokenizer.c,v 1.6 2000/09/04 22:06:33 lukem Exp $ */
+/* $NetBSD: tokenizer.c,v 1.7 2001/01/04 15:56:32 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: tokenizer.c,v 1.6 2000/09/04 22:06:33 lukem Exp $");
+__RCSID("$NetBSD: tokenizer.c,v 1.7 2001/01/04 15:56:32 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -114,8 +114,12 @@ tok_init(const char *ifs)
tok->argc = 0;
tok->amax = AINCR;
tok->argv = (char **) tok_malloc(sizeof(char *) * tok->amax);
+ if (tok->argv == NULL)
+ return (NULL);
tok->argv[0] = NULL;
tok->wspace = (char *) tok_malloc(WINCR);
+ if (tok->wspace == NULL)
+ return (NULL);
tok->wmax = tok->wspace + WINCR;
tok->wstart = tok->wspace;
tok->wptr = tok->wspace;
@@ -368,6 +372,8 @@ tok_line(Tokenizer *tok, const char *line, int *argc, char ***argv)
char *s = (char *) tok_realloc(tok->wspace, size);
/* SUPPRESS 22 */
int offs = s - tok->wspace;
+ if (s == NULL)
+ return (-1);
if (offs != 0) {
int i;
@@ -380,9 +386,13 @@ tok_line(Tokenizer *tok, const char *line, int *argc, char ***argv)
}
}
if (tok->argc >= tok->amax - 4) {
+ char **p;
tok->amax += AINCR;
- tok->argv = (char **) tok_realloc(tok->argv,
+ p = (char **) tok_realloc(tok->argv,
tok->amax * sizeof(char *));
+ if (p == NULL)
+ return (-1);
+ tok->argv = p;
}
}
}