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 /lib/libedit/tokenizer.c | |
parent | 6346db23bda7041e13c4664e7cd282aa4280cbcd (diff) |
deal with realloc/malloc failure and don't trash old pointer if realloc fails
Diffstat (limited to 'lib/libedit/tokenizer.c')
-rw-r--r-- | lib/libedit/tokenizer.c | 18 |
1 files changed, 10 insertions, 8 deletions
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; + } } - } } |