change allocation policy in el_push to allocate the string itself.
fix issues with strdup.
This commit is contained in:
parent
e1c37edb37
commit
6e782349a3
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: chared.c,v 1.19 2003/08/07 16:44:30 agc Exp $ */
|
||||
/* $NetBSD: chared.c,v 1.20 2003/10/18 23:48:42 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: chared.c,v 1.19 2003/08/07 16:44:30 agc Exp $");
|
||||
__RCSID("$NetBSD: chared.c,v 1.20 2003/10/18 23:48:42 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -456,8 +456,8 @@ ch_init(EditLine *el)
|
|||
el->el_state.argument = 1;
|
||||
el->el_state.lastcmd = ED_UNASSIGNED;
|
||||
|
||||
el->el_chared.c_macro.nline = NULL;
|
||||
el->el_chared.c_macro.level = -1;
|
||||
el->el_chared.c_macro.offset = 0;
|
||||
el->el_chared.c_macro.macro = (char **) el_malloc(EL_MAXMACRO *
|
||||
sizeof(char *));
|
||||
if (el->el_chared.c_macro.macro == NULL)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: chared.h,v 1.12 2003/08/07 16:44:30 agc Exp $ */
|
||||
/* $NetBSD: chared.h,v 1.13 2003/10/18 23:48:42 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -62,8 +62,8 @@
|
|||
|
||||
typedef struct c_macro_t {
|
||||
int level;
|
||||
int offset;
|
||||
char **macro;
|
||||
char *nline;
|
||||
} c_macro_t;
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: el.c,v 1.35 2003/10/16 22:26:32 christos Exp $ */
|
||||
/* $NetBSD: el.c,v 1.36 2003/10/18 23:48:42 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: el.c,v 1.35 2003/10/16 22:26:32 christos Exp $");
|
||||
__RCSID("$NetBSD: el.c,v 1.36 2003/10/18 23:48:42 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -68,7 +68,10 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
|
|||
el->el_infd = fileno(fin);
|
||||
el->el_outfile = fout;
|
||||
el->el_errfile = ferr;
|
||||
el->el_prog = strdup(prog);
|
||||
if ((el->el_prog = el_strdup(prog)) == NULL) {
|
||||
el_free(el);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize all the modules. Order is important!!!
|
||||
|
@ -76,7 +79,7 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
|
|||
el->el_flags = 0;
|
||||
|
||||
if (term_init(el) == -1) {
|
||||
free(el->el_prog);
|
||||
el_free(el->el_prog);
|
||||
el_free(el);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: el.h,v 1.15 2003/09/26 17:44:51 christos Exp $ */
|
||||
/* $NetBSD: el.h,v 1.16 2003/10/18 23:48:42 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -88,6 +88,7 @@ typedef struct el_state_t {
|
|||
/*
|
||||
* Until we come up with something better...
|
||||
*/
|
||||
#define el_strdup(a) strdup(a)
|
||||
#define el_malloc(a) malloc(a)
|
||||
#define el_realloc(a,b) realloc(a, b)
|
||||
#define el_free(a) free(a)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: history.c,v 1.24 2003/08/07 16:44:31 agc Exp $ */
|
||||
/* $NetBSD: history.c,v 1.25 2003/10/18 23:48:42 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: history.c,v 1.24 2003/08/07 16:44:31 agc Exp $");
|
||||
__RCSID("$NetBSD: history.c,v 1.25 2003/10/18 23:48:42 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -87,6 +87,7 @@ struct history {
|
|||
#define HENTER(h, ev, str) (*(h)->h_enter)((h)->h_ref, ev, str)
|
||||
#define HADD(h, ev, str) (*(h)->h_add)((h)->h_ref, ev, str)
|
||||
|
||||
#define h_strdup(a) strdup(a)
|
||||
#define h_malloc(a) malloc(a)
|
||||
#define h_realloc(a, b) realloc((a), (b))
|
||||
#define h_free(a) free(a)
|
||||
|
@ -394,7 +395,7 @@ history_def_insert(history_t *h, HistEvent *ev, const char *str)
|
|||
h->cursor = (hentry_t *) h_malloc(sizeof(hentry_t));
|
||||
if (h->cursor == NULL)
|
||||
goto oomem;
|
||||
if ((h->cursor->ev.str = strdup(str)) == NULL) {
|
||||
if ((h->cursor->ev.str = h_strdup(str)) == NULL) {
|
||||
h_free((ptr_t)h->cursor);
|
||||
goto oomem;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: key.c,v 1.14 2003/08/07 16:44:31 agc Exp $ */
|
||||
/* $NetBSD: key.c,v 1.15 2003/10/18 23:48:42 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)key.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: key.c,v 1.14 2003/08/07 16:44:31 agc Exp $");
|
||||
__RCSID("$NetBSD: key.c,v 1.15 2003/10/18 23:48:42 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -352,7 +352,8 @@ node__try(EditLine *el, key_node_t *ptr, const char *str, key_value_t *val, int
|
|||
break;
|
||||
case XK_STR:
|
||||
case XK_EXE:
|
||||
ptr->val.str = strdup(val->str);
|
||||
if ((ptr->val.str = el_strdup(val->str)) == NULL)
|
||||
return -1;
|
||||
break;
|
||||
default:
|
||||
EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: read.c,v 1.29 2003/10/09 00:42:28 christos Exp $ */
|
||||
/* $NetBSD: read.c,v 1.30 2003/10/18 23:48:42 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: read.c,v 1.29 2003/10/09 00:42:28 christos Exp $");
|
||||
__RCSID("$NetBSD: read.c,v 1.30 2003/10/18 23:48:42 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -187,10 +187,6 @@ read_preread(EditLine *el)
|
|||
{
|
||||
int chrs = 0;
|
||||
|
||||
if (el->el_chared.c_macro.nline) {
|
||||
el_free((ptr_t) el->el_chared.c_macro.nline);
|
||||
el->el_chared.c_macro.nline = NULL;
|
||||
}
|
||||
if (el->el_tty.t_mode == ED_IO)
|
||||
return (0);
|
||||
|
||||
|
@ -203,8 +199,7 @@ read_preread(EditLine *el)
|
|||
(size_t) MIN(chrs, EL_BUFSIZ - 1));
|
||||
if (chrs > 0) {
|
||||
buf[chrs] = '\0';
|
||||
el->el_chared.c_macro.nline = strdup(buf);
|
||||
el_push(el, el->el_chared.c_macro.nline);
|
||||
el_push(el, buf);
|
||||
}
|
||||
}
|
||||
#endif /* FIONREAD */
|
||||
|
@ -223,11 +218,12 @@ el_push(EditLine *el, char *str)
|
|||
|
||||
if (str != NULL && ma->level + 1 < EL_MAXMACRO) {
|
||||
ma->level++;
|
||||
ma->macro[ma->level] = str;
|
||||
} else {
|
||||
term_beep(el);
|
||||
term__flush();
|
||||
if ((ma->macro[ma->level] = el_strdup(str)) != NULL)
|
||||
return;
|
||||
ma->level--;
|
||||
}
|
||||
term_beep(el);
|
||||
term__flush();
|
||||
}
|
||||
|
||||
|
||||
|
@ -324,14 +320,16 @@ el_getc(EditLine *el, char *cp)
|
|||
if (ma->level < 0)
|
||||
break;
|
||||
|
||||
if (*ma->macro[ma->level] == 0) {
|
||||
ma->level--;
|
||||
if (ma->macro[ma->level][ma->offset] == '\0') {
|
||||
el_free(ma->macro[ma->level--]);
|
||||
ma->offset = 0;
|
||||
continue;
|
||||
}
|
||||
*cp = *ma->macro[ma->level]++ & 0377;
|
||||
if (*ma->macro[ma->level] == 0) { /* Needed for QuoteMode
|
||||
* On */
|
||||
ma->level--;
|
||||
*cp = ma->macro[ma->level][ma->offset++] & 0377;
|
||||
if (ma->macro[ma->level][ma->offset] == '\0') {
|
||||
/* Needed for QuoteMode On */
|
||||
el_free(ma->macro[ma->level--]);
|
||||
ma->offset = 0;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: tokenizer.c,v 1.12 2003/08/07 16:44:34 agc Exp $ */
|
||||
/* $NetBSD: tokenizer.c,v 1.13 2003/10/18 23:48:42 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: tokenizer.c,v 1.12 2003/08/07 16:44:34 agc Exp $");
|
||||
__RCSID("$NetBSD: tokenizer.c,v 1.13 2003/10/18 23:48:42 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -60,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)
|
||||
|
@ -107,7 +108,7 @@ tok_init(const char *ifs)
|
|||
|
||||
if (tok == NULL)
|
||||
return NULL;
|
||||
tok->ifs = strdup(ifs ? ifs : IFS);
|
||||
tok->ifs = tok_strdup(ifs ? ifs : IFS);
|
||||
if (tok->ifs == NULL) {
|
||||
tok_free((ptr_t)tok);
|
||||
return NULL;
|
||||
|
|
Loading…
Reference in New Issue