Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/lib/libedit/tokenizer.c,v rcsdiff: /ftp/cvs/cvsroot/src/lib/libedit/tokenizer.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.7 retrieving revision 1.13 diff -u -p -r1.7 -r1.13 --- src/lib/libedit/tokenizer.c 2001/01/04 15:56:32 1.7 +++ src/lib/libedit/tokenizer.c 2003/10/18 23:48:42 1.13 @@ -1,4 +1,4 @@ -/* $NetBSD: tokenizer.c,v 1.7 2001/01/04 15:56:32 christos Exp $ */ +/* $NetBSD: tokenizer.c,v 1.13 2003/10/18 23:48:42 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,19 +32,18 @@ * SUCH DAMAGE. */ -#include +#include "config.h" #if !defined(lint) && !defined(SCCSID) #if 0 static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: tokenizer.c,v 1.7 2001/01/04 15:56:32 christos Exp $"); +__RCSID("$NetBSD: tokenizer.c,v 1.13 2003/10/18 23:48:42 christos Exp $"); #endif #endif /* not lint && not SCCSID */ /* * tokenize.c: Bourne shell like tokenizer */ -#include "sys.h" #include #include #include "tokenizer.h" @@ -65,6 +60,7 @@ typedef enum { #define WINCR 20 #define AINCR 10 +#define tok_strdup(a) strdup(a) #define tok_malloc(a) malloc(a) #define tok_free(a) free(a) #define tok_realloc(a, b) realloc(a, b) @@ -110,16 +106,29 @@ tok_init(const char *ifs) { Tokenizer *tok = (Tokenizer *) tok_malloc(sizeof(Tokenizer)); - tok->ifs = strdup(ifs ? ifs : IFS); + if (tok == NULL) + return NULL; + tok->ifs = tok_strdup(ifs ? ifs : IFS); + if (tok->ifs == NULL) { + tok_free((ptr_t)tok); + return NULL; + } tok->argc = 0; tok->amax = AINCR; tok->argv = (char **) tok_malloc(sizeof(char *) * tok->amax); - if (tok->argv == NULL) - return (NULL); + if (tok->argv == NULL) { + tok_free((ptr_t)tok->ifs); + tok_free((ptr_t)tok); + return NULL; + } tok->argv[0] = NULL; tok->wspace = (char *) tok_malloc(WINCR); - if (tok->wspace == NULL) - return (NULL); + if (tok->wspace == NULL) { + tok_free((ptr_t)tok->argv); + tok_free((ptr_t)tok->ifs); + tok_free((ptr_t)tok); + return NULL; + } tok->wmax = tok->wspace + WINCR; tok->wstart = tok->wspace; tok->wptr = tok->wspace; @@ -170,7 +179,7 @@ tok_end(Tokenizer *tok) * 0: Ok */ public int -tok_line(Tokenizer *tok, const char *line, int *argc, char ***argv) +tok_line(Tokenizer *tok, const char *line, int *argc, const char ***argv) { const char *ptr; @@ -275,7 +284,7 @@ tok_line(Tokenizer *tok, const char *lin switch (tok->quote) { case Q_none: tok_finish(tok); - *argv = tok->argv; + *argv = (const char **)tok->argv; *argc = tok->argc; return (0); @@ -308,7 +317,7 @@ tok_line(Tokenizer *tok, const char *lin return (3); } tok_finish(tok); - *argv = tok->argv; + *argv = (const char **)tok->argv; *argc = tok->argc; return (0); @@ -370,20 +379,20 @@ tok_line(Tokenizer *tok, const char *lin if (tok->wptr >= tok->wmax - 4) { size_t size = tok->wmax - tok->wspace + WINCR; char *s = (char *) tok_realloc(tok->wspace, size); - /* SUPPRESS 22 */ - int offs = s - tok->wspace; if (s == NULL) return (-1); - if (offs != 0) { + if (s != tok->wspace) { int i; - for (i = 0; i < tok->argc; i++) - tok->argv[i] = tok->argv[i] + offs; - tok->wptr = tok->wptr + offs; - tok->wstart = tok->wstart + offs; - tok->wmax = s + size; + for (i = 0; i < tok->argc; i++) { + tok->argv[i] = + (tok->argv[i] - tok->wspace) + s; + } + tok->wptr = (tok->wptr - tok->wspace) + s; + tok->wstart = (tok->wstart - tok->wspace) + s; tok->wspace = s; } + tok->wmax = s + size; } if (tok->argc >= tok->amax - 4) { char **p;