diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1998-08-16 20:24:55 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1998-08-16 20:24:55 +0000 |
commit | 637e272642a676fbed4c100b96dec275cf89a275 (patch) | |
tree | 0af36f0019cccd68d90afb71d4b3a6f18827b533 | |
parent | 6346db23bda7041e13c4664e7cd282aa4280cbcd (diff) |
deal with realloc/malloc failure and don't trash old pointer if realloc fails
-rw-r--r-- | lib/libedit/map.c | 16 | ||||
-rw-r--r-- | lib/libedit/tokenizer.c | 18 |
2 files changed, 20 insertions, 14 deletions
diff --git a/lib/libedit/map.c b/lib/libedit/map.c index 67ef9ebaa47..44e68607d5a 100644 --- a/lib/libedit/map.c +++ b/lib/libedit/map.c @@ -1,4 +1,4 @@ -/* $OpenBSD: map.c,v 1.3 1997/03/14 05:12:54 millert Exp $ */ +/* $OpenBSD: map.c,v 1.4 1998/08/16 20:24:53 millert Exp $ */ /* $NetBSD: map.c,v 1.3 1997/01/11 06:48:00 lukem Exp $ */ /*- @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93"; #else -static char rcsid[] = "$OpenBSD: map.c,v 1.3 1997/03/14 05:12:54 millert Exp $"; +static char rcsid[] = "$OpenBSD: map.c,v 1.4 1998/08/16 20:24:53 millert Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -1382,14 +1382,18 @@ map_addfunc(el, name, help, func) 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/tokenizer.c b/lib/libedit/tokenizer.c index ed7b8e7b79a..22f25145060 100644 --- a/lib/libedit/tokenizer.c +++ b/lib/libedit/tokenizer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tokenizer.c,v 1.3 1997/03/14 05:13:07 millert Exp $ */ +/* $OpenBSD: tokenizer.c,v 1.4 1998/08/16 20:24:54 millert Exp $ */ /* $NetBSD: tokenizer.c,v 1.2 1997/01/11 06:48:15 lukem Exp $ */ /*- @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93"; #else -static char rcsid[] = "$OpenBSD: tokenizer.c,v 1.3 1997/03/14 05:13:07 millert Exp $"; +static char rcsid[] = "$OpenBSD: tokenizer.c,v 1.4 1998/08/16 20:24:54 millert Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -369,9 +369,9 @@ tok_line(tok, line, argc, argv) size_t size = tok->wmax - tok->wspace + WINCR; char *s = (char *) tok_realloc(tok->wspace, size); /*SUPPRESS 22*/ - int offs = s - tok->wspace; + int offs; - if (offs != 0) { + if (s != NULL && (offs = s - tok->wspace) != 0) { int i; for (i = 0; i < tok->argc; i++) tok->argv[i] = tok->argv[i] + offs; @@ -383,10 +383,12 @@ tok_line(tok, line, argc, argv) } if (tok->argc >= tok->amax - 4) { - tok->amax += AINCR; - tok->argv = (char **) tok_realloc(tok->argv, - tok->amax * sizeof(char*)); + char **nargv = (char **) tok_realloc(tok->argv, (tok->amax + AINCR) + * sizeof(char*)); + if (nargv != NULL) { + tok->amax += AINCR; + tok->argv = nargv; + } } - } } |