diff options
-rw-r--r-- | lib/libedit/chared.c | 89 | ||||
-rw-r--r-- | lib/libedit/chartype.c | 22 | ||||
-rw-r--r-- | lib/libedit/chartype.h | 4 | ||||
-rw-r--r-- | lib/libedit/el.c | 22 | ||||
-rw-r--r-- | lib/libedit/el.h | 9 | ||||
-rw-r--r-- | lib/libedit/filecomplete.c | 10 | ||||
-rw-r--r-- | lib/libedit/hist.c | 9 | ||||
-rw-r--r-- | lib/libedit/history.c | 41 | ||||
-rw-r--r-- | lib/libedit/key.c | 17 | ||||
-rw-r--r-- | lib/libedit/map.c | 26 | ||||
-rw-r--r-- | lib/libedit/parse.c | 6 | ||||
-rw-r--r-- | lib/libedit/read.c | 4 | ||||
-rw-r--r-- | lib/libedit/search.c | 6 | ||||
-rw-r--r-- | lib/libedit/sig.c | 6 | ||||
-rw-r--r-- | lib/libedit/term.c | 54 | ||||
-rw-r--r-- | lib/libedit/tokenizer.c | 36 | ||||
-rw-r--r-- | lib/libedit/vi.c | 16 |
17 files changed, 181 insertions, 196 deletions
diff --git a/lib/libedit/chared.c b/lib/libedit/chared.c index 71495037e30..044314b6169 100644 --- a/lib/libedit/chared.c +++ b/lib/libedit/chared.c @@ -1,4 +1,4 @@ -/* $OpenBSD: chared.c,v 1.11 2011/07/07 05:40:42 okan Exp $ */ +/* $OpenBSD: chared.c,v 1.12 2014/10/17 06:07:50 deraadt Exp $ */ /* $NetBSD: chared.c,v 1.28 2009/12/30 22:37:40 christos Exp $ */ /*- @@ -445,58 +445,59 @@ ch_init(EditLine *el) { c_macro_t *ma = &el->el_chared.c_macro; - el->el_line.buffer = el_malloc(EL_BUFSIZ * + el->el_line.buffer = reallocarray(NULL, EL_BUFSIZ, sizeof(*el->el_line.buffer)); if (el->el_line.buffer == NULL) return (-1); (void) memset(el->el_line.buffer, 0, EL_BUFSIZ * sizeof(*el->el_line.buffer)); - 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 - EL_LEAVE]; + 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 - EL_LEAVE]; - el->el_chared.c_undo.buf = el_malloc(EL_BUFSIZ * + el->el_chared.c_undo.buf = reallocarray(NULL, EL_BUFSIZ, sizeof(*el->el_chared.c_undo.buf)); if (el->el_chared.c_undo.buf == NULL) return (-1); (void) memset(el->el_chared.c_undo.buf, 0, EL_BUFSIZ * sizeof(*el->el_chared.c_undo.buf)); - el->el_chared.c_undo.len = -1; - el->el_chared.c_undo.cursor = 0; - el->el_chared.c_redo.buf = el_malloc(EL_BUFSIZ * + el->el_chared.c_undo.len = -1; + el->el_chared.c_undo.cursor = 0; + el->el_chared.c_redo.buf = reallocarray(NULL, EL_BUFSIZ, sizeof(*el->el_chared.c_redo.buf)); if (el->el_chared.c_redo.buf == NULL) return (-1); - el->el_chared.c_redo.pos = el->el_chared.c_redo.buf; - el->el_chared.c_redo.lim = el->el_chared.c_redo.buf + EL_BUFSIZ; - el->el_chared.c_redo.cmd = ED_UNASSIGNED; + el->el_chared.c_redo.pos = el->el_chared.c_redo.buf; + el->el_chared.c_redo.lim = el->el_chared.c_redo.buf + EL_BUFSIZ; + el->el_chared.c_redo.cmd = ED_UNASSIGNED; - el->el_chared.c_vcmd.action = NOP; - el->el_chared.c_vcmd.pos = el->el_line.buffer; + el->el_chared.c_vcmd.action = NOP; + el->el_chared.c_vcmd.pos = el->el_line.buffer; - el->el_chared.c_kill.buf = el_malloc(EL_BUFSIZ * + el->el_chared.c_kill.buf = reallocarray(NULL, EL_BUFSIZ, sizeof(*el->el_chared.c_kill.buf)); if (el->el_chared.c_kill.buf == NULL) return (-1); (void) memset(el->el_chared.c_kill.buf, 0, EL_BUFSIZ * sizeof(*el->el_chared.c_kill.buf)); - el->el_chared.c_kill.mark = el->el_line.buffer; - el->el_chared.c_kill.last = el->el_chared.c_kill.buf; - el->el_chared.c_resizefun = NULL; - el->el_chared.c_resizearg = NULL; - - el->el_map.current = el->el_map.key; - - el->el_state.inputmode = MODE_INSERT; /* XXX: save a default */ - el->el_state.doingarg = 0; - el->el_state.metanext = 0; - el->el_state.argument = 1; - el->el_state.lastcmd = ED_UNASSIGNED; - - ma->level = -1; - ma->offset = 0; - ma->macro = el_malloc(EL_MAXMACRO * sizeof(*ma->macro)); + el->el_chared.c_kill.mark = el->el_line.buffer; + el->el_chared.c_kill.last = el->el_chared.c_kill.buf; + el->el_chared.c_resizefun = NULL; + el->el_chared.c_resizearg = NULL; + + el->el_map.current = el->el_map.key; + + el->el_state.inputmode = MODE_INSERT; /* XXX: save a default */ + el->el_state.doingarg = 0; + el->el_state.metanext = 0; + el->el_state.argument = 1; + el->el_state.lastcmd = ED_UNASSIGNED; + + ma->level = -1; + ma->offset = 0; + ma->macro = reallocarray(NULL, EL_MAXMACRO, + sizeof(*ma->macro)); if (ma->macro == NULL) return (-1); return (0); @@ -538,7 +539,7 @@ ch__clearmacro(EditLine *el) { c_macro_t *ma = &el->el_chared.c_macro; while (ma->level >= 0) - el_free((ptr_t)ma->macro[ma->level--]); + free((ptr_t)ma->macro[ma->level--]); } /* ch_enlargebufs(): @@ -565,7 +566,8 @@ ch_enlargebufs(EditLine *el, size_t addlen) /* * Reallocate line buffer. */ - newbuffer = el_realloc(el->el_line.buffer, newsz * sizeof(*newbuffer)); + newbuffer = reallocarray(el->el_line.buffer, newsz, + sizeof(*newbuffer)); if (!newbuffer) return 0; @@ -583,7 +585,8 @@ ch_enlargebufs(EditLine *el, size_t addlen) /* * Reallocate kill buffer. */ - newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz * sizeof(*newbuffer)); + newbuffer = reallocarray(el->el_chared.c_kill.buf, newsz, + sizeof(*newbuffer)); if (!newbuffer) return 0; @@ -601,8 +604,8 @@ ch_enlargebufs(EditLine *el, size_t addlen) /* * Reallocate undo buffer. */ - newbuffer = el_realloc(el->el_chared.c_undo.buf, - newsz * sizeof(*newbuffer)); + newbuffer = reallocarray(el->el_chared.c_undo.buf, + newsz, sizeof(*newbuffer)); if (!newbuffer) return 0; @@ -610,8 +613,8 @@ ch_enlargebufs(EditLine *el, size_t addlen) (void) memset(&newbuffer[sz], 0, (newsz - sz) * sizeof(*newbuffer)); el->el_chared.c_undo.buf = newbuffer; - newbuffer = el_realloc(el->el_chared.c_redo.buf, - newsz * sizeof(*newbuffer)); + newbuffer = reallocarray(el->el_chared.c_redo.buf, + newsz, sizeof(*newbuffer)); if (!newbuffer) return 0; el->el_chared.c_redo.pos = newbuffer + @@ -636,20 +639,20 @@ ch_enlargebufs(EditLine *el, size_t addlen) protected void ch_end(EditLine *el) { - el_free((ptr_t) el->el_line.buffer); + free((ptr_t) el->el_line.buffer); el->el_line.buffer = NULL; el->el_line.limit = NULL; - el_free((ptr_t) el->el_chared.c_undo.buf); + free((ptr_t) el->el_chared.c_undo.buf); el->el_chared.c_undo.buf = NULL; - el_free((ptr_t) el->el_chared.c_redo.buf); + free((ptr_t) el->el_chared.c_redo.buf); el->el_chared.c_redo.buf = NULL; el->el_chared.c_redo.pos = NULL; el->el_chared.c_redo.lim = NULL; el->el_chared.c_redo.cmd = ED_UNASSIGNED; - el_free((ptr_t) el->el_chared.c_kill.buf); + free((ptr_t) el->el_chared.c_kill.buf); el->el_chared.c_kill.buf = NULL; ch_reset(el, 1); - el_free((ptr_t) el->el_chared.c_macro.macro); + free((ptr_t) el->el_chared.c_macro.macro); el->el_chared.c_macro.macro = NULL; } diff --git a/lib/libedit/chartype.c b/lib/libedit/chartype.c index 6a028af8c4e..272e7b89ce9 100644 --- a/lib/libedit/chartype.c +++ b/lib/libedit/chartype.c @@ -1,4 +1,4 @@ -/* $OpenBSD: chartype.c,v 1.5 2013/05/22 00:31:38 yasuoka Exp $ */ +/* $OpenBSD: chartype.c,v 1.6 2014/10/17 06:07:50 deraadt Exp $ */ /* $NetBSD: chartype.c,v 1.6 2011/07/28 00:48:21 christos Exp $ */ /*- @@ -50,10 +50,10 @@ ct_conv_buff_resize(ct_buffer_t *conv, size_t mincsize, size_t minwsize) void *p; if (mincsize > conv->csize) { conv->csize = mincsize; - p = el_realloc(conv->cbuff, conv->csize * sizeof(char)); + p = reallocarray(conv->cbuff, conv->csize, sizeof(char)); if (p == NULL) { conv->csize = 0; - el_free(conv->cbuff); + free(conv->cbuff); conv->cbuff = NULL; } else conv->cbuff = p; @@ -61,10 +61,10 @@ ct_conv_buff_resize(ct_buffer_t *conv, size_t mincsize, size_t minwsize) if (minwsize > conv->wsize) { conv->wsize = minwsize; - p = el_realloc(conv->wbuff, conv->wsize * sizeof(Char)); + p = reallocarray(conv->wbuff, conv->wsize, sizeof(Char)); if (p == NULL) { conv->wsize = 0; - el_free(conv->wbuff); + free(conv->wbuff); conv->wbuff = NULL; } else conv->wbuff = p; @@ -146,7 +146,7 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer_t *conv) if (!conv->wsize) return NULL; - wargv = el_malloc(argc * sizeof(*wargv)); + wargv = reallocarray(NULL, argc, sizeof(*wargv)); for (i = 0, p = conv->wbuff; i < argc; ++i) { if (!argv[i]) { /* don't pass null pointers to mbstowcs */ @@ -158,7 +158,7 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer_t *conv) } if (wlen == (size_t)-1 || wlen == bufspace) { /* Encoding error or not enough room for NUL. */ - el_free(wargv); + free(wargv); return NULL; } else wlen++; /* include NUL in the count */ @@ -215,7 +215,7 @@ ct_visual_string(const Char *s) return NULL; if (!buff) { buffsize = CT_BUFSIZ; - buff = el_malloc(buffsize * sizeof(*buff)); + buff = reallocarray(NULL, buffsize, sizeof(*buff)); } dst = buff; while (*s) { @@ -223,7 +223,7 @@ ct_visual_string(const Char *s) if (used == -1) { /* failed to encode, need more buffer space */ used = dst - buff; buffsize += CT_BUFSIZ; - p = el_realloc(buff, buffsize * sizeof(*buff)); + p = reallocarray(buff, buffsize, sizeof(*buff)); if (p == NULL) goto out; buff = p; @@ -236,7 +236,7 @@ ct_visual_string(const Char *s) } if (dst >= (buff + buffsize)) { /* sigh */ buffsize += 1; - p = el_realloc(buff, buffsize * sizeof(*buff)); + p = reallocarray(buff, buffsize, sizeof(*buff)); if (p == NULL) goto out; buff = p; @@ -245,7 +245,7 @@ ct_visual_string(const Char *s) *dst = 0; return buff; out: - el_free(buff); + free(buff); buffsize = 0; return NULL; } diff --git a/lib/libedit/chartype.h b/lib/libedit/chartype.h index 83fafa2b15a..505fa7b436f 100644 --- a/lib/libedit/chartype.h +++ b/lib/libedit/chartype.h @@ -1,4 +1,4 @@ -/* $OpenBSD: chartype.h,v 1.4 2011/07/07 16:15:47 nicm Exp $ */ +/* $OpenBSD: chartype.h,v 1.5 2014/10/17 06:07:50 deraadt Exp $ */ /* $NetBSD: chartype.h,v 1.5 2010/04/15 00:55:57 christos Exp $ */ /*- @@ -189,7 +189,7 @@ protected void ct_conv_buff_resize(ct_buffer_t *, size_t, size_t); protected ssize_t ct_encode_char(char *, size_t, Char); protected size_t ct_enc_width(Char); -#define ct_free_argv(s) el_free(s) +#define ct_free_argv(s) free(s) #else #define ct_encode_string(s, b) (s) diff --git a/lib/libedit/el.c b/lib/libedit/el.c index 5433615feb8..bdbbd80a588 100644 --- a/lib/libedit/el.c +++ b/lib/libedit/el.c @@ -1,4 +1,4 @@ -/* $OpenBSD: el.c,v 1.18 2011/07/13 11:05:17 otto Exp $ */ +/* $OpenBSD: el.c,v 1.19 2014/10/17 06:07:50 deraadt Exp $ */ /* $NetBSD: el.c,v 1.61 2011/01/27 23:11:40 christos Exp $ */ /*- @@ -54,7 +54,7 @@ public EditLine * el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr) { - EditLine *el = (EditLine *) el_malloc(sizeof(EditLine)); + EditLine *el = (EditLine *) malloc(sizeof(EditLine)); if (el == NULL) return (NULL); @@ -71,7 +71,7 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr) el->el_prog = Strdup(ct_decode_string(prog, &el->el_scratch)); if (el->el_prog == NULL) { - el_free(el); + free(el); return NULL; } @@ -87,8 +87,8 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr) #endif if (term_init(el) == -1) { - el_free(el->el_prog); - el_free(el); + free(el->el_prog); + free(el); return NULL; } (void) key_init(el); @@ -128,14 +128,14 @@ el_end(EditLine *el) prompt_end(el); sig_end(el); - el_free((ptr_t) el->el_prog); + free((ptr_t) el->el_prog); #ifdef WIDECHAR - el_free((ptr_t) el->el_scratch.cbuff); - el_free((ptr_t) el->el_scratch.wbuff); - el_free((ptr_t) el->el_lgcyconv.cbuff); - el_free((ptr_t) el->el_lgcyconv.wbuff); + free((ptr_t) el->el_scratch.cbuff); + free((ptr_t) el->el_scratch.wbuff); + free((ptr_t) el->el_lgcyconv.cbuff); + free((ptr_t) el->el_lgcyconv.wbuff); #endif - el_free((ptr_t) el); + free((ptr_t) el); } diff --git a/lib/libedit/el.h b/lib/libedit/el.h index 189b619b90d..092527d99c8 100644 --- a/lib/libedit/el.h +++ b/lib/libedit/el.h @@ -1,4 +1,4 @@ -/* $OpenBSD: el.h,v 1.8 2011/07/07 05:40:42 okan Exp $ */ +/* $OpenBSD: el.h,v 1.9 2014/10/17 06:07:50 deraadt Exp $ */ /* $NetBSD: el.h,v 1.21 2009/12/31 15:58:26 christos Exp $ */ /*- @@ -92,13 +92,6 @@ typedef struct el_state_t { Char thisch; /* char that generated it */ } el_state_t; -/* - * Until we come up with something better... - */ -#define el_malloc(a) malloc(a) -#define el_realloc(a,b) realloc(a, b) -#define el_free(a) free(a) - #include "tty.h" #include "prompt.h" #include "key.h" diff --git a/lib/libedit/filecomplete.c b/lib/libedit/filecomplete.c index a6de8de79fa..5eda39113c6 100644 --- a/lib/libedit/filecomplete.c +++ b/lib/libedit/filecomplete.c @@ -1,4 +1,4 @@ -/* $OpenBSD: filecomplete.c,v 1.3 2014/10/11 03:10:06 doug Exp $ */ +/* $OpenBSD: filecomplete.c,v 1.4 2014/10/17 06:07:50 deraadt Exp $ */ /* $NetBSD: filecomplete.c,v 1.22 2010/12/02 04:42:46 dholland Exp $ */ /*- @@ -433,11 +433,7 @@ fn_complete(EditLine *el, ctemp--; len = li->cursor - ctemp; -#if defined(__SSP__) || defined(__SSP_ALL__) - temp = malloc(sizeof(*temp) * (len + 1)); -#else - temp = alloca(sizeof(*temp) * (len + 1)); -#endif + temp = reallocarray(NULL, len + 1, sizeof(*temp)); (void)Strncpy(temp, ctemp, len); temp[len] = '\0'; @@ -552,9 +548,7 @@ fn_complete(EditLine *el, free(matches); matches = NULL; } -#if defined(__SSP__) || defined(__SSP_ALL__) free(temp); -#endif return retval; } diff --git a/lib/libedit/hist.c b/lib/libedit/hist.c index 7d38be971ae..a749bc2c381 100644 --- a/lib/libedit/hist.c +++ b/lib/libedit/hist.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hist.c,v 1.9 2010/06/30 00:05:35 nicm Exp $ */ +/* $OpenBSD: hist.c,v 1.10 2014/10/17 06:07:50 deraadt Exp $ */ /* $NetBSD: hist.c,v 1.17 2009/12/30 23:54:52 christos Exp $ */ /*- @@ -50,7 +50,8 @@ hist_init(EditLine *el) el->el_history.fun = NULL; el->el_history.ref = NULL; - el->el_history.buf = el_malloc(EL_BUFSIZ * sizeof(*el->el_history.buf)); + el->el_history.buf = reallocarray(NULL, EL_BUFSIZ, + sizeof(*el->el_history.buf)); el->el_history.sz = EL_BUFSIZ; if (el->el_history.buf == NULL) return (-1); @@ -66,7 +67,7 @@ protected void hist_end(EditLine *el) { - el_free((ptr_t) el->el_history.buf); + free((ptr_t) el->el_history.buf); el->el_history.buf = NULL; } @@ -190,7 +191,7 @@ hist_enlargebuf(EditLine *el, size_t oldsz, size_t newsz) { Char *newbuf; - newbuf = el_realloc(el->el_history.buf, newsz * sizeof(*newbuf)); + newbuf = reallocarray(el->el_history.buf, newsz, sizeof(*newbuf)); if (!newbuf) return 0; diff --git a/lib/libedit/history.c b/lib/libedit/history.c index 1c8290b621f..a8d3a518b06 100644 --- a/lib/libedit/history.c +++ b/lib/libedit/history.c @@ -1,4 +1,4 @@ -/* $OpenBSD: history.c,v 1.18 2014/05/19 08:58:34 nicm Exp $ */ +/* $OpenBSD: history.c,v 1.19 2014/10/17 06:07:50 deraadt Exp $ */ /* $NetBSD: history.c,v 1.37 2010/01/03 18:27:10 christos Exp $ */ /*- @@ -85,9 +85,6 @@ struct TYPE(history) { #define HDEL(h, ev, n) (*(h)->h_del)((h)->h_ref, ev, n) #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) typedef struct { int num; @@ -379,7 +376,7 @@ history_def_add(ptr_t p, TYPE(HistEvent) *ev, const Char *str) if (h->cursor == &h->list) return (history_def_enter(p, ev, str)); len = Strlen(evp->str) + Strlen(str) + 1; - s = h_malloc(len * sizeof(*s)); + s = reallocarray(NULL, len, sizeof(*s)); if (s == NULL) { he_seterrev(ev, _HE_MALLOC_FAILED); return (-1); @@ -387,7 +384,7 @@ history_def_add(ptr_t p, TYPE(HistEvent) *ev, const Char *str) (void) Strncpy(s, h->cursor->ev.str, len); s[len - 1] = '\0'; (void) Strncat(s, str, len - Strlen(s) - 1); - h_free((ptr_t)evp->str); + free((ptr_t)evp->str); evp->str = s; *ev = h->cursor->ev; return (0); @@ -448,8 +445,8 @@ history_def_delete(history_t *h, } hp->prev->next = hp->next; hp->next->prev = hp->prev; - h_free((ptr_t) evp->str); - h_free(hp); + free((ptr_t) evp->str); + free(hp); h->cur--; } @@ -461,11 +458,11 @@ private int history_def_insert(history_t *h, TYPE(HistEvent) *ev, const Char *str) { - h->cursor = (hentry_t *) h_malloc(sizeof(hentry_t)); + h->cursor = (hentry_t *) malloc(sizeof(hentry_t)); if (h->cursor == NULL) goto oomem; if ((h->cursor->ev.str = h_strdup(str)) == NULL) { - h_free((ptr_t)h->cursor); + free((ptr_t)h->cursor); goto oomem; } h->cursor->data = NULL; @@ -517,7 +514,7 @@ history_def_enter(ptr_t p, TYPE(HistEvent) *ev, const Char *str) private int history_def_init(ptr_t *p, TYPE(HistEvent) *ev __attribute__((__unused__)), int n) { - history_t *h = (history_t *) h_malloc(sizeof(history_t)); + history_t *h = (history_t *) malloc(sizeof(history_t)); if (h == NULL) return -1; @@ -562,12 +559,12 @@ public TYPE(History) * FUN(history,init)(void) { TYPE(HistEvent) ev; - TYPE(History) *h = (TYPE(History) *) h_malloc(sizeof(TYPE(History))); + TYPE(History) *h = (TYPE(History) *) malloc(sizeof(TYPE(History))); if (h == NULL) return NULL; if (history_def_init(&h->h_ref, &ev, 0) == -1) { - h_free((ptr_t)h); + free((ptr_t)h); return NULL; } h->h_ent = -1; @@ -596,8 +593,8 @@ FUN(history,end)(TYPE(History) *h) if (h->h_next == history_def_next) history_def_clear(h->h_ref, &ev); - h_free(h->h_ref); - h_free(h); + free(h->h_ref); + free(h); } @@ -744,7 +741,7 @@ history_load(TYPE(History) *h, const char *fname) if (strncmp(line, hist_cookie, sz) != 0) goto done; - ptr = h_malloc(max_size = 1024); + ptr = malloc(max_size = 1024); if (ptr == NULL) goto done; for (i = 0; (line = fgetln(fp, &sz)) != NULL; i++) { @@ -763,7 +760,7 @@ history_load(TYPE(History) *h, const char *fname) if (sz > max_size) { char *nptr; max_size = (sz + 1024) & ~1023; - nptr = h_realloc(ptr, max_size); + nptr = realloc(ptr, max_size); if (nptr == NULL) { i = -1; goto oomem; @@ -777,9 +774,9 @@ history_load(TYPE(History) *h, const char *fname) } } oomem: - h_free((ptr_t)ptr); + free((ptr_t)ptr); done: - h_free(lbuf); + free(lbuf); (void) fclose(fp); return (i); } @@ -803,7 +800,7 @@ history_save_fp(TYPE(History) *h, FILE *fp) goto done; if (fputs(hist_cookie, fp) == EOF) goto done; - ptr = h_malloc(max_size = 1024); + ptr = malloc(max_size = 1024); if (ptr == NULL) goto done; for (i = 0, retval = HLAST(h, &ev); @@ -813,7 +810,7 @@ history_save_fp(TYPE(History) *h, FILE *fp) if (len > max_size) { char *nptr; max_size = (len + 1024) & ~1023; - nptr = h_realloc(ptr, max_size); + nptr = realloc(ptr, max_size); if (nptr == NULL) { i = -1; goto oomem; @@ -825,7 +822,7 @@ history_save_fp(TYPE(History) *h, FILE *fp) (void) fprintf(fp, "%s\n", ptr); } oomem: - h_free((ptr_t)ptr); + free((ptr_t)ptr); done: return (i); } diff --git a/lib/libedit/key.c b/lib/libedit/key.c index 40ded0a2549..acf614ee12f 100644 --- a/lib/libedit/key.c +++ b/lib/libedit/key.c @@ -1,4 +1,4 @@ -/* $OpenBSD: key.c,v 1.11 2010/06/30 00:05:35 nicm Exp $ */ +/* $OpenBSD: key.c,v 1.12 2014/10/17 06:07:50 deraadt Exp $ */ /* $NetBSD: key.c,v 1.23 2009/12/30 22:37:40 christos Exp $ */ /*- @@ -96,7 +96,8 @@ protected int key_init(EditLine *el) { - el->el_key.buf = el_malloc(KEY_BUFSIZ * sizeof(*el->el_key.buf)); + el->el_key.buf = reallocarray(NULL, KEY_BUFSIZ, + sizeof(*el->el_key.buf)); if (el->el_key.buf == NULL) return (-1); el->el_key.map = NULL; @@ -111,7 +112,7 @@ protected void key_end(EditLine *el) { - el_free((ptr_t) el->el_key.buf); + free((ptr_t) el->el_key.buf); el->el_key.buf = NULL; node__free(el->el_key.map); } @@ -333,7 +334,7 @@ node__try(EditLine *el, key_node_t *ptr, const Char *str, key_value_t *val, int case XK_STR: case XK_EXE: if (ptr->val.str) - el_free((ptr_t) ptr->val.str); + free((ptr_t) ptr->val.str); break; default: EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", @@ -434,13 +435,13 @@ node__put(EditLine *el, key_node_t *ptr) case XK_EXE: case XK_STR: if (ptr->val.str != NULL) - el_free((ptr_t) ptr->val.str); + free((ptr_t) ptr->val.str); break; default: EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ptr->type)); break; } - el_free((ptr_t) ptr); + free((ptr_t) ptr); } @@ -452,7 +453,7 @@ node__get(Int ch) { key_node_t *ptr; - ptr = (key_node_t *) el_malloc((size_t) sizeof(key_node_t)); + ptr = malloc(sizeof(key_node_t)); if (ptr == NULL) return NULL; ptr->ch = ch; @@ -470,7 +471,7 @@ node__free(key_node_t *k) return; node__free(k->sibling); node__free(k->next); - el_free((ptr_t) k); + free((ptr_t) k); } /* node_lookup(): diff --git a/lib/libedit/map.c b/lib/libedit/map.c index ffe2c9e5a67..a9a6c0e7378 100644 --- a/lib/libedit/map.c +++ b/lib/libedit/map.c @@ -1,4 +1,4 @@ -/* $OpenBSD: map.c,v 1.11 2010/06/30 00:05:35 nicm Exp $ */ +/* $OpenBSD: map.c,v 1.12 2014/10/17 06:07:50 deraadt Exp $ */ /* $NetBSD: map.c,v 1.25 2009/12/30 22:37:40 christos Exp $ */ /*- @@ -897,23 +897,23 @@ map_init(EditLine *el) EL_ABORT((el->errfile, "Vi insert map incorrect\n")); #endif - el->el_map.alt = (el_action_t *)el_malloc(sizeof(el_action_t) * N_KEYS); + el->el_map.alt = reallocarray(NULL, N_KEYS, sizeof(el_action_t)); if (el->el_map.alt == NULL) return (-1); - el->el_map.key = (el_action_t *)el_malloc(sizeof(el_action_t) * N_KEYS); + el->el_map.key = reallocarray(NULL, N_KEYS, sizeof(el_action_t)); 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); + el->el_map.help = reallocarray(NULL, EL_NUM_FCNS, + sizeof(el_bindings_t)); 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_NUM_FCNS); + el->el_map.func = reallocarray(NULL, EL_NUM_FCNS, + sizeof(el_func_t)); if (el->el_map.func == NULL) return (-1); memcpy(el->el_map.func, func__get(), sizeof(el_func_t) * EL_NUM_FCNS); @@ -935,16 +935,16 @@ protected void map_end(EditLine *el) { - el_free((ptr_t) el->el_map.alt); + free((ptr_t) el->el_map.alt); el->el_map.alt = NULL; - el_free((ptr_t) el->el_map.key); + free((ptr_t) el->el_map.key); el->el_map.key = NULL; el->el_map.emacs = NULL; el->el_map.vic = NULL; el->el_map.vii = NULL; - el_free((ptr_t) el->el_map.help); + free((ptr_t) el->el_map.help); el->el_map.help = NULL; - el_free((ptr_t) el->el_map.func); + free((ptr_t) el->el_map.func); el->el_map.func = NULL; } @@ -1395,10 +1395,10 @@ map_addfunc(EditLine *el, const Char *name, const Char *help, el_func_t func) if (name == NULL || help == NULL || func == NULL) return (-1); - if ((p = el_realloc(el->el_map.func, nf * sizeof(el_func_t))) == NULL) + if ((p = reallocarray(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))) + if ((p = reallocarray(el->el_map.help, nf, sizeof(el_bindings_t))) == NULL) return (-1); el->el_map.help = (el_bindings_t *) p; diff --git a/lib/libedit/parse.c b/lib/libedit/parse.c index 9a2d6808139..45b386428c7 100644 --- a/lib/libedit/parse.c +++ b/lib/libedit/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.11 2011/11/27 21:46:44 pascal Exp $ */ +/* $OpenBSD: parse.c,v 1.12 2014/10/17 06:07:50 deraadt Exp $ */ /* $NetBSD: parse.c,v 1.23 2009/12/30 22:37:40 christos Exp $ */ /*- @@ -103,14 +103,14 @@ FUN(el,parse)(EditLine *el, int argc, const Char *argv[]) if (ptr == argv[0]) return (0); l = ptr - argv[0] - 1; - tprog = el_malloc((l + 1) * sizeof(*tprog)); + tprog = reallocarray(NULL, l + 1, sizeof(*tprog)); if (tprog == NULL) return (0); (void) Strncpy(tprog, argv[0], l); tprog[l] = '\0'; ptr++; l = el_match(el->el_prog, tprog); - el_free(tprog); + free(tprog); if (!l) return (0); } else diff --git a/lib/libedit/read.c b/lib/libedit/read.c index f7c9bda8f5b..20dcc7aa733 100644 --- a/lib/libedit/read.c +++ b/lib/libedit/read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read.c,v 1.14 2011/07/07 05:40:42 okan Exp $ */ +/* $OpenBSD: read.c,v 1.15 2014/10/17 06:07:50 deraadt Exp $ */ /* $NetBSD: read.c,v 1.57 2010/07/21 18:18:52 christos Exp $ */ /*- @@ -366,7 +366,7 @@ read_pop(c_macro_t *ma) { int i; - el_free(ma->macro[0]); + free(ma->macro[0]); for (i = 0; i < ma->level; i++) ma->macro[i] = ma->macro[i + 1]; ma->level--; diff --git a/lib/libedit/search.c b/lib/libedit/search.c index 6af282ae3f9..9cd740e0e00 100644 --- a/lib/libedit/search.c +++ b/lib/libedit/search.c @@ -1,4 +1,4 @@ -/* $OpenBSD: search.c,v 1.12 2010/06/30 00:05:35 nicm Exp $ */ +/* $OpenBSD: search.c,v 1.13 2014/10/17 06:07:50 deraadt Exp $ */ /* $NetBSD: search.c,v 1.24 2010/04/15 00:57:33 christos Exp $ */ /*- @@ -60,7 +60,7 @@ protected int search_init(EditLine *el) { - el->el_search.patbuf = el_malloc(EL_BUFSIZ * + el->el_search.patbuf = reallocarray(NULL, EL_BUFSIZ, sizeof(*el->el_search.patbuf)); if (el->el_search.patbuf == NULL) return (-1); @@ -80,7 +80,7 @@ protected void search_end(EditLine *el) { - el_free((ptr_t) el->el_search.patbuf); + free((ptr_t) el->el_search.patbuf); el->el_search.patbuf = NULL; } diff --git a/lib/libedit/sig.c b/lib/libedit/sig.c index b36e0725d10..05562b8a3cc 100644 --- a/lib/libedit/sig.c +++ b/lib/libedit/sig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sig.c,v 1.13 2011/06/03 23:34:56 deraadt Exp $ */ +/* $OpenBSD: sig.c,v 1.14 2014/10/17 06:07:50 deraadt Exp $ */ /* $NetBSD: sig.c,v 1.15 2009/02/19 15:20:22 christos Exp $ */ /*- @@ -111,7 +111,7 @@ sig_init(EditLine *el) size_t i; sigset_t *nset, oset; - el->el_signal = el_malloc(sizeof(*el->el_signal)); + el->el_signal = malloc(sizeof(*el->el_signal)); if (el->el_signal == NULL) return -1; @@ -141,7 +141,7 @@ protected void sig_end(EditLine *el) { - el_free((ptr_t) el->el_signal); + free((ptr_t) el->el_signal); el->el_signal = NULL; } diff --git a/lib/libedit/term.c b/lib/libedit/term.c index 4606e95b0b1..cde70db608c 100644 --- a/lib/libedit/term.c +++ b/lib/libedit/term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term.c,v 1.16 2014/01/19 11:48:54 tobias Exp $ */ +/* $OpenBSD: term.c,v 1.17 2014/10/17 06:07:50 deraadt Exp $ */ /* $NetBSD: term.c,v 1.57 2009/12/30 22:37:40 christos Exp $ */ /*- @@ -331,21 +331,21 @@ protected int term_init(EditLine *el) { - el->el_term.t_buf = (char *) el_malloc(TC_BUFSIZE); + el->el_term.t_buf = (char *)malloc(TC_BUFSIZE); if (el->el_term.t_buf == NULL) goto fail; - el->el_term.t_cap = (char *) el_malloc(TC_BUFSIZE); + el->el_term.t_cap = (char *)malloc(TC_BUFSIZE); if (el->el_term.t_cap == NULL) goto fail2; - el->el_term.t_fkey = (fkey_t *) el_malloc(A_K_NKEYS * sizeof(fkey_t)); + el->el_term.t_fkey = reallocarray(NULL, A_K_NKEYS, sizeof(fkey_t)); if (el->el_term.t_fkey == NULL) goto fail3; el->el_term.t_loc = 0; - el->el_term.t_str = (char **) el_malloc(T_str * sizeof(char *)); + el->el_term.t_str = reallocarray(NULL, T_str, sizeof(char *)); if (el->el_term.t_str == NULL) goto fail4; (void) memset(el->el_term.t_str, 0, T_str * sizeof(char *)); - el->el_term.t_val = (int *) el_malloc(T_val * sizeof(int)); + el->el_term.t_val = reallocarray(NULL, T_val, sizeof(int)); if (el->el_term.t_val == NULL) goto fail5; (void) memset(el->el_term.t_val, 0, T_val * sizeof(int)); @@ -353,16 +353,16 @@ term_init(EditLine *el) term_init_arrow(el); return (0); fail5: - el_free(el->el_term.t_str); + free(el->el_term.t_str); el->el_term.t_str = NULL; fail4: - el_free(el->el_term.t_fkey); + free(el->el_term.t_fkey); el->el_term.t_fkey = NULL; fail3: - el_free(el->el_term.t_cap); + free(el->el_term.t_cap); el->el_term.t_cap = NULL; fail2: - el_free(el->el_term.t_buf); + free(el->el_term.t_buf); el->el_term.t_buf = NULL; fail: return (-1); @@ -375,16 +375,16 @@ protected void term_end(EditLine *el) { - el_free((ptr_t) el->el_term.t_buf); + free((ptr_t) el->el_term.t_buf); el->el_term.t_buf = NULL; - el_free((ptr_t) el->el_term.t_cap); + free((ptr_t) el->el_term.t_cap); el->el_term.t_cap = NULL; el->el_term.t_loc = 0; - el_free((ptr_t) el->el_term.t_str); + free((ptr_t) el->el_term.t_str); el->el_term.t_str = NULL; - el_free((ptr_t) el->el_term.t_val); + free((ptr_t) el->el_term.t_val); el->el_term.t_val = NULL; - el_free((ptr_t) el->el_term.t_fkey); + free((ptr_t) el->el_term.t_fkey); el->el_term.t_fkey = NULL; term_free_display(el); } @@ -483,30 +483,30 @@ term_alloc_display(EditLine *el) Char **b; coord_t *c = &el->el_term.t_size; - b = el_malloc(sizeof(*b) * (c->v + 1)); + b = reallocarray(NULL, c->v + 1, sizeof(*b)); if (b == NULL) goto done; for (i = 0; i < c->v; i++) { - b[i] = el_malloc(sizeof(**b) * (c->h + 1)); + b[i] = reallocarray(NULL, c->h + 1, sizeof(**b)); if (b[i] == NULL) { while (--i >= 0) - el_free((ptr_t) b[i]); - el_free((ptr_t) b); + free((ptr_t) b[i]); + free((ptr_t) b); goto done; } } b[c->v] = NULL; el->el_display = b; - b = el_malloc(sizeof(*b) * (c->v + 1)); + b = reallocarray(NULL, c->v + 1, sizeof(*b)); if (b == NULL) goto done; for (i = 0; i < c->v; i++) { - b[i] = el_malloc(sizeof(**b) * (c->h + 1)); + b[i] = reallocarray(NULL, c->h + 1, sizeof(**b)); if (b[i] == NULL) { while (--i >= 0) - el_free((ptr_t) b[i]); - el_free((ptr_t) b); + free((ptr_t) b[i]); + free((ptr_t) b); goto done; } } @@ -534,15 +534,15 @@ term_free_display(EditLine *el) el->el_display = NULL; if (b != NULL) { for (bufp = b; *bufp != NULL; bufp++) - el_free((ptr_t) *bufp); - el_free((ptr_t) b); + free((ptr_t) *bufp); + free((ptr_t) b); } b = el->el_vdisplay; el->el_vdisplay = NULL; if (b != NULL) { for (bufp = b; *bufp != NULL; bufp++) - el_free((ptr_t) *bufp); - el_free((ptr_t) b); + free((ptr_t) *bufp); + free((ptr_t) b); } } diff --git a/lib/libedit/tokenizer.c b/lib/libedit/tokenizer.c index efd72af5e80..409e387c1d5 100644 --- a/lib/libedit/tokenizer.c +++ b/lib/libedit/tokenizer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tokenizer.c,v 1.12 2010/06/30 00:05:35 nicm Exp $ */ +/* $OpenBSD: tokenizer.c,v 1.13 2014/10/17 06:07:50 deraadt Exp $ */ /* $NetBSD: tokenizer.c,v 1.18 2010/01/03 18:27:10 christos Exp $ */ /*- @@ -56,9 +56,6 @@ typedef enum { #define IFS STR("\t \n") -#define tok_malloc(a) malloc(a) -#define tok_free(a) free(a) -#define tok_realloc(a, b) realloc(a, b) #define tok_strdup(a) Strdup(a) @@ -100,29 +97,29 @@ FUN(tok,finish)(TYPE(Tokenizer) *tok) public TYPE(Tokenizer) * FUN(tok,init)(const Char *ifs) { - TYPE(Tokenizer) *tok = tok_malloc(sizeof(TYPE(Tokenizer))); + TYPE(Tokenizer) *tok = malloc(sizeof(TYPE(Tokenizer))); if (tok == NULL) return NULL; tok->ifs = tok_strdup(ifs ? ifs : IFS); if (tok->ifs == NULL) { - tok_free((ptr_t)tok); + free((ptr_t)tok); return NULL; } tok->argc = 0; tok->amax = AINCR; - tok->argv = tok_malloc(sizeof(*tok->argv) * tok->amax); + tok->argv = reallocarray(NULL, tok->amax, sizeof(*tok->argv)); if (tok->argv == NULL) { - tok_free((ptr_t)tok->ifs); - tok_free((ptr_t)tok); + free((ptr_t)tok->ifs); + free((ptr_t)tok); return NULL; } tok->argv[0] = NULL; - tok->wspace = tok_malloc(WINCR * sizeof(*tok->wspace)); + tok->wspace = reallocarray(NULL, WINCR, sizeof(*tok->wspace)); if (tok->wspace == NULL) { - tok_free((ptr_t)tok->argv); - tok_free((ptr_t)tok->ifs); - tok_free((ptr_t)tok); + free((ptr_t)tok->argv); + free((ptr_t)tok->ifs); + free((ptr_t)tok); return NULL; } tok->wmax = tok->wspace + WINCR; @@ -157,10 +154,10 @@ public void FUN(tok,end)(TYPE(Tokenizer) *tok) { - tok_free((ptr_t) tok->ifs); - tok_free((ptr_t) tok->wspace); - tok_free((ptr_t) tok->argv); - tok_free((ptr_t) tok); + free((ptr_t) tok->ifs); + free((ptr_t) tok->wspace); + free((ptr_t) tok->argv); + free((ptr_t) tok); } @@ -386,8 +383,7 @@ FUN(tok,line)(TYPE(Tokenizer) *tok, const TYPE(LineInfo) *line, if (tok->wptr >= tok->wmax - 4) { size_t size = tok->wmax - tok->wspace + WINCR; - Char *s = tok_realloc(tok->wspace, - size * sizeof(*s)); + Char *s = reallocarray(tok->wspace, size, sizeof(*s)); if (s == NULL) return (-1); @@ -406,7 +402,7 @@ FUN(tok,line)(TYPE(Tokenizer) *tok, const TYPE(LineInfo) *line, if (tok->argc >= tok->amax - 4) { Char **p; tok->amax += AINCR; - p = tok_realloc(tok->argv, tok->amax * sizeof(*p)); + p = reallocarray(tok->argv, tok->amax, sizeof(*p)); if (p == NULL) return (-1); tok->argv = p; diff --git a/lib/libedit/vi.c b/lib/libedit/vi.c index cb17e859cab..a960e4290f6 100644 --- a/lib/libedit/vi.c +++ b/lib/libedit/vi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vi.c,v 1.11 2011/07/07 05:40:42 okan Exp $ */ +/* $OpenBSD: vi.c,v 1.12 2014/10/17 06:07:50 deraadt Exp $ */ /* $NetBSD: vi.c,v 1.33 2011/02/17 16:44:48 joerg Exp $ */ /*- @@ -1013,17 +1013,17 @@ vi_histedit(EditLine *el, Int c) return CC_ERROR; len = (size_t)(el->el_line.lastchar - el->el_line.buffer); #define TMP_BUFSIZ (EL_BUFSIZ * MB_LEN_MAX) - cp = el_malloc(TMP_BUFSIZ); + cp = malloc(TMP_BUFSIZ); if (cp == NULL) { close(fd); unlink(tempfile); return CC_ERROR; } - line = el_malloc(len * sizeof(*line)); + line = reallocarray(NULL, len, sizeof(*line)); if (line == NULL) { close(fd); unlink(tempfile); - el_free((ptr_t)cp); + free((ptr_t)cp); return CC_ERROR; } Strncpy(line, el->el_line.buffer, len); @@ -1038,8 +1038,8 @@ vi_histedit(EditLine *el, Int c) case -1: close(fd); unlink(tempfile); - el_free(cp); - el_free(line); + free(cp); + free(line); return CC_ERROR; case 0: close(fd); @@ -1062,8 +1062,8 @@ vi_histedit(EditLine *el, Int c) len = 0; el->el_line.cursor = el->el_line.buffer; el->el_line.lastchar = el->el_line.buffer + len; - el_free(cp); - el_free(line); + free(cp); + free(line); break; } |