PR/54399: Sören Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b)) to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
This commit is contained in:
parent
4d25743b11
commit
113f06a345
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: chared.c,v 1.58 2019/07/23 09:47:16 christos Exp $ */
|
||||
/* $NetBSD: chared.c,v 1.59 2019/07/23 10:18:52 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.58 2019/07/23 09:47:16 christos Exp $");
|
||||
__RCSID("$NetBSD: chared.c,v 1.59 2019/07/23 10:18:52 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -396,26 +396,22 @@ cv__endword(wchar_t *p, wchar_t *high, int n, int (*wtest)(wint_t))
|
|||
libedit_private int
|
||||
ch_init(EditLine *el)
|
||||
{
|
||||
el->el_line.buffer = el_malloc(EL_BUFSIZ *
|
||||
el->el_line.buffer = el_calloc(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_chared.c_undo.buf = el_malloc(EL_BUFSIZ *
|
||||
el->el_chared.c_undo.buf = el_calloc(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_redo.buf = el_calloc(EL_BUFSIZ,
|
||||
sizeof(*el->el_chared.c_redo.buf));
|
||||
if (el->el_chared.c_redo.buf == NULL)
|
||||
return -1;
|
||||
|
@ -426,12 +422,10 @@ ch_init(EditLine *el)
|
|||
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 = el_calloc(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;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: chartype.c,v 1.34 2018/11/25 16:20:28 christos Exp $ */
|
||||
/* $NetBSD: chartype.c,v 1.35 2019/07/23 10:18:52 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009 The NetBSD Foundation, Inc.
|
||||
|
@ -31,7 +31,7 @@
|
|||
*/
|
||||
#include "config.h"
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
__RCSID("$NetBSD: chartype.c,v 1.34 2018/11/25 16:20:28 christos Exp $");
|
||||
__RCSID("$NetBSD: chartype.c,v 1.35 2019/07/23 10:18:52 christos Exp $");
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
#include <ctype.h>
|
||||
|
@ -157,7 +157,7 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer_t *conv)
|
|||
if (ct_conv_wbuff_resize(conv, bufspace + CT_BUFSIZ) == -1)
|
||||
return NULL;
|
||||
|
||||
wargv = el_malloc((size_t)(argc + 1) * sizeof(*wargv));
|
||||
wargv = el_calloc((size_t)(argc + 1), sizeof(*wargv));
|
||||
|
||||
for (i = 0, p = conv->wbuff; i < argc; ++i) {
|
||||
if (!argv[i]) { /* don't pass null pointers to mbstowcs */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: el.c,v 1.98 2019/04/26 16:56:57 christos Exp $ */
|
||||
/* $NetBSD: el.c,v 1.99 2019/07/23 10:18:52 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.98 2019/04/26 16:56:57 christos Exp $");
|
||||
__RCSID("$NetBSD: el.c,v 1.99 2019/07/23 10:18:52 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -71,13 +71,11 @@ libedit_private EditLine *
|
|||
el_init_internal(const char *prog, FILE *fin, FILE *fout, FILE *ferr,
|
||||
int fdin, int fdout, int fderr, int flags)
|
||||
{
|
||||
EditLine *el = el_malloc(sizeof(*el));
|
||||
EditLine *el = el_calloc(1, sizeof(*el));
|
||||
|
||||
if (el == NULL)
|
||||
return NULL;
|
||||
|
||||
memset(el, 0, sizeof(EditLine));
|
||||
|
||||
el->el_infile = fin;
|
||||
el->el_outfile = fout;
|
||||
el->el_errfile = ferr;
|
||||
|
@ -534,7 +532,7 @@ el_source(EditLine *el, const char *fname)
|
|||
if ((ptr = getenv("HOME")) == NULL)
|
||||
return -1;
|
||||
plen += strlen(ptr);
|
||||
if ((path = el_malloc(plen * sizeof(*path))) == NULL)
|
||||
if ((path = el_calloc(plen, sizeof(*path))) == NULL)
|
||||
return -1;
|
||||
(void)snprintf(path, plen, "%s%s", ptr,
|
||||
elpath + (*ptr == '\0'));
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: el.h,v 1.44 2018/11/18 17:09:39 christos Exp $ */
|
||||
/* $NetBSD: el.h,v 1.45 2019/07/23 10:18:52 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -89,6 +89,7 @@ typedef struct el_state_t {
|
|||
* Until we come up with something better...
|
||||
*/
|
||||
#define el_malloc(a) malloc(a)
|
||||
#define el_calloc(a,b) calloc(a, b)
|
||||
#define el_realloc(a,b) realloc(a, b)
|
||||
#define el_free(a) free(a)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: filecomplete.c,v 1.55 2019/04/20 08:44:10 abhinav Exp $ */
|
||||
/* $NetBSD: filecomplete.c,v 1.56 2019/07/23 10:18:52 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997 The NetBSD Foundation, Inc.
|
||||
|
@ -31,7 +31,7 @@
|
|||
|
||||
#include "config.h"
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
__RCSID("$NetBSD: filecomplete.c,v 1.55 2019/04/20 08:44:10 abhinav Exp $");
|
||||
__RCSID("$NetBSD: filecomplete.c,v 1.56 2019/07/23 10:18:52 christos Exp $");
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -83,7 +83,7 @@ fn_tilde_expand(const char *txt)
|
|||
} else {
|
||||
/* text until string after slash */
|
||||
len = (size_t)(temp - txt + 1);
|
||||
temp = el_malloc(len * sizeof(*temp));
|
||||
temp = el_calloc(len, sizeof(*temp));
|
||||
if (temp == NULL)
|
||||
return NULL;
|
||||
(void)strncpy(temp, txt + 1, len - 2);
|
||||
|
@ -118,7 +118,7 @@ fn_tilde_expand(const char *txt)
|
|||
txt += len;
|
||||
|
||||
len = strlen(pass->pw_dir) + 1 + strlen(txt) + 1;
|
||||
temp = el_malloc(len * sizeof(*temp));
|
||||
temp = el_calloc(len, sizeof(*temp));
|
||||
if (temp == NULL)
|
||||
return NULL;
|
||||
(void)snprintf(temp, len, "%s/%s", pass->pw_dir, txt);
|
||||
|
@ -179,7 +179,7 @@ unescape_string(const wchar_t *string, size_t length)
|
|||
{
|
||||
size_t i;
|
||||
size_t j = 0;
|
||||
wchar_t *unescaped = el_malloc(sizeof(*string) * (length + 1));
|
||||
wchar_t *unescaped = el_calloc(length + 1, sizeof(*string));
|
||||
if (unescaped == NULL)
|
||||
return NULL;
|
||||
for (i = 0; i < length ; i++) {
|
||||
|
@ -410,7 +410,7 @@ fn_filename_completion_function(const char *text, int state)
|
|||
#endif
|
||||
|
||||
len = strlen(dirname) + len + 1;
|
||||
temp = el_malloc(len * sizeof(*temp));
|
||||
temp = el_calloc(len, sizeof(*temp));
|
||||
if (temp == NULL)
|
||||
return NULL;
|
||||
(void)snprintf(temp, len, "%s%s", dirname, entry->d_name);
|
||||
|
@ -486,7 +486,7 @@ completion_matches(const char *text, char *(*genfunc)(const char *, int))
|
|||
max_equal = i;
|
||||
}
|
||||
|
||||
retstr = el_malloc((max_equal + 1) * sizeof(*retstr));
|
||||
retstr = el_calloc(max_equal + 1, sizeof(*retstr));
|
||||
if (retstr == NULL) {
|
||||
el_free(match_list);
|
||||
return NULL;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: hist.c,v 1.32 2017/03/05 19:23:58 christos Exp $ */
|
||||
/* $NetBSD: hist.c,v 1.33 2019/07/23 10:18:52 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: hist.c,v 1.32 2017/03/05 19:23:58 christos Exp $");
|
||||
__RCSID("$NetBSD: hist.c,v 1.33 2019/07/23 10:18:52 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -59,7 +59,7 @@ 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 = el_calloc(EL_BUFSIZ, sizeof(*el->el_history.buf));
|
||||
el->el_history.sz = EL_BUFSIZ;
|
||||
if (el->el_history.buf == NULL)
|
||||
return -1;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: keymacro.c,v 1.23 2016/05/24 15:00:45 christos Exp $ */
|
||||
/* $NetBSD: keymacro.c,v 1.24 2019/07/23 10:18:52 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: keymacro.c,v 1.23 2016/05/24 15:00:45 christos Exp $");
|
||||
__RCSID("$NetBSD: keymacro.c,v 1.24 2019/07/23 10:18:52 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -105,7 +105,7 @@ libedit_private int
|
|||
keymacro_init(EditLine *el)
|
||||
{
|
||||
|
||||
el->el_keymacro.buf = el_malloc(KEY_BUFSIZ *
|
||||
el->el_keymacro.buf = el_calloc(KEY_BUFSIZ,
|
||||
sizeof(*el->el_keymacro.buf));
|
||||
if (el->el_keymacro.buf == NULL)
|
||||
return -1;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: literal.c,v 1.3 2017/06/30 20:26:52 kre Exp $ */
|
||||
/* $NetBSD: literal.c,v 1.4 2019/07/23 10:18:52 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2017 The NetBSD Foundation, Inc.
|
||||
|
@ -31,7 +31,7 @@
|
|||
|
||||
#include "config.h"
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
__RCSID("$NetBSD: literal.c,v 1.3 2017/06/30 20:26:52 kre Exp $");
|
||||
__RCSID("$NetBSD: literal.c,v 1.4 2019/07/23 10:18:52 christos Exp $");
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
/*
|
||||
|
@ -97,9 +97,9 @@ literal_add(EditLine *el, const wchar_t *buf, const wchar_t *end, int *wp)
|
|||
if (b == NULL)
|
||||
return 0;
|
||||
|
||||
for (n = 0, i = 0; i < len; i++)
|
||||
n += ct_encode_char(b + n, w - n, buf[i]);
|
||||
n += ct_encode_char(b + n, w - n, end[1]);
|
||||
for (n = 0, i = 0; i < len; i++) {
|
||||
n += ct_encode_char(b + n, (size_t)(w - n), buf[i]);
|
||||
n += ct_encode_char(b + n, (size_t)(w - n), end[1]);
|
||||
b[n] = '\0';
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: map.c,v 1.51 2016/05/09 21:46:56 christos Exp $ */
|
||||
/* $NetBSD: map.c,v 1.52 2019/07/23 10:18:52 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: map.c,v 1.51 2016/05/09 21:46:56 christos Exp $");
|
||||
__RCSID("$NetBSD: map.c,v 1.52 2019/07/23 10:18:52 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -913,21 +913,21 @@ map_init(EditLine *el)
|
|||
EL_ABORT((el->errfile, "Vi insert map incorrect\n"));
|
||||
#endif
|
||||
|
||||
el->el_map.alt = el_malloc(sizeof(*el->el_map.alt) * N_KEYS);
|
||||
el->el_map.alt = el_calloc(N_KEYS, sizeof(*el->el_map.alt));
|
||||
if (el->el_map.alt == NULL)
|
||||
return -1;
|
||||
el->el_map.key = el_malloc(sizeof(*el->el_map.key) * N_KEYS);
|
||||
el->el_map.key = el_calloc(N_KEYS, sizeof(*el->el_map.key));
|
||||
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_malloc(sizeof(*el->el_map.help) * EL_NUM_FCNS);
|
||||
el->el_map.help = el_calloc(EL_NUM_FCNS, sizeof(*el->el_map.help));
|
||||
if (el->el_map.help == NULL)
|
||||
return -1;
|
||||
(void) memcpy(el->el_map.help, el_func_help,
|
||||
sizeof(*el->el_map.help) * EL_NUM_FCNS);
|
||||
el->el_map.func = el_malloc(sizeof(*el->el_map.func) * EL_NUM_FCNS);
|
||||
el->el_map.func = el_calloc(EL_NUM_FCNS, sizeof(*el->el_map.func));
|
||||
if (el->el_map.func == NULL)
|
||||
return -1;
|
||||
memcpy(el->el_map.func, el_func, sizeof(*el->el_map.func)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: parse.c,v 1.41 2018/11/29 03:10:20 christos Exp $ */
|
||||
/* $NetBSD: parse.c,v 1.42 2019/07/23 10:18:52 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: parse.c,v 1.41 2018/11/29 03:10:20 christos Exp $");
|
||||
__RCSID("$NetBSD: parse.c,v 1.42 2019/07/23 10:18:52 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -112,7 +112,7 @@ el_wparse(EditLine *el, int argc, const wchar_t *argv[])
|
|||
if (ptr == argv[0])
|
||||
return 0;
|
||||
l = (size_t)(ptr - argv[0]);
|
||||
tprog = el_malloc((l + 1) * sizeof(*tprog));
|
||||
tprog = el_calloc(l + 1, sizeof(*tprog));
|
||||
if (tprog == NULL)
|
||||
return 0;
|
||||
(void) wcsncpy(tprog, argv[0], l);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: read.c,v 1.105 2018/11/25 16:21:04 christos Exp $ */
|
||||
/* $NetBSD: read.c,v 1.106 2019/07/23 10:18:52 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.105 2018/11/25 16:21:04 christos Exp $");
|
||||
__RCSID("$NetBSD: read.c,v 1.106 2019/07/23 10:18:52 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -89,8 +89,7 @@ read_init(EditLine *el)
|
|||
return -1;
|
||||
|
||||
ma = &el->el_read->macros;
|
||||
if ((ma->macro = el_malloc(EL_MAXMACRO *
|
||||
sizeof(*ma->macro))) == NULL) {
|
||||
if ((ma->macro = el_calloc(EL_MAXMACRO, sizeof(*ma->macro))) == NULL) {
|
||||
free(el->el_read);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: readline.c,v 1.155 2019/06/07 15:21:48 christos Exp $ */
|
||||
/* $NetBSD: readline.c,v 1.156 2019/07/23 10:18:52 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997 The NetBSD Foundation, Inc.
|
||||
|
@ -31,7 +31,7 @@
|
|||
|
||||
#include "config.h"
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
__RCSID("$NetBSD: readline.c,v 1.155 2019/06/07 15:21:48 christos Exp $");
|
||||
__RCSID("$NetBSD: readline.c,v 1.156 2019/07/23 10:18:52 christos Exp $");
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -515,7 +515,7 @@ _rl_compat_sub(const char *str, const char *what, const char *with,
|
|||
} else
|
||||
s++;
|
||||
}
|
||||
r = result = el_malloc((len + 1) * sizeof(*r));
|
||||
r = result = el_calloc(len + 1, sizeof(*r));
|
||||
if (result == NULL)
|
||||
return NULL;
|
||||
s = str;
|
||||
|
@ -605,7 +605,7 @@ get_history_event(const char *cmd, int *cindex, int qchar)
|
|||
else if (len == 0)
|
||||
return NULL;
|
||||
else {
|
||||
if ((pat = el_malloc((len + 1) * sizeof(*pat))) == NULL)
|
||||
if ((pat = el_calloc(len + 1, sizeof(*pat))) == NULL)
|
||||
return NULL;
|
||||
(void)strncpy(pat, cmd + begin, len);
|
||||
pat[len] = '\0';
|
||||
|
@ -699,7 +699,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
|
|||
} else {
|
||||
if (command[offs + 1] == '#') {
|
||||
/* use command so far */
|
||||
if ((aptr = el_malloc((offs + 1) * sizeof(*aptr)))
|
||||
if ((aptr = el_calloc(offs + 1, sizeof(*aptr)))
|
||||
== NULL)
|
||||
return -1;
|
||||
(void)strncpy(aptr, command, offs);
|
||||
|
@ -933,7 +933,7 @@ history_expand(char *str, char **output)
|
|||
*output = NULL;
|
||||
if (str[0] == history_subst_char) {
|
||||
/* ^foo^foo2^ is equivalent to !!:s^foo^foo2^ */
|
||||
*output = el_malloc((strlen(str) + 4 + 1) * sizeof(**output));
|
||||
*output = el_calloc(strlen(str) + 4 + 1, sizeof(**output));
|
||||
if (*output == NULL)
|
||||
return 0;
|
||||
(*output)[0] = (*output)[1] = history_expansion_char;
|
||||
|
@ -1081,7 +1081,7 @@ history_arg_extract(int start, int end, const char *str)
|
|||
for (i = (size_t)start, len = 0; i <= (size_t)end; i++)
|
||||
len += strlen(arr[i]) + 1;
|
||||
len++;
|
||||
result = el_malloc(len * sizeof(*result));
|
||||
result = el_calloc(len, sizeof(*result));
|
||||
if (result == NULL)
|
||||
goto out;
|
||||
|
||||
|
@ -1143,7 +1143,7 @@ history_tokenize(const char *str)
|
|||
result = nresult;
|
||||
}
|
||||
len = (size_t)i - (size_t)start;
|
||||
temp = el_malloc((size_t)(len + 1) * sizeof(*temp));
|
||||
temp = el_calloc(len + 1, sizeof(*temp));
|
||||
if (temp == NULL) {
|
||||
for (i = 0; i < idx; i++)
|
||||
el_free(result[i]);
|
||||
|
@ -2267,7 +2267,7 @@ rl_completion_matches(const char *str, rl_compentry_func_t *fun)
|
|||
|
||||
len = 1;
|
||||
max = 10;
|
||||
if ((list = el_malloc(max * sizeof(*list))) == NULL)
|
||||
if ((list = el_calloc(max, sizeof(*list))) == NULL)
|
||||
return NULL;
|
||||
|
||||
while ((match = (*fun)(str, (int)(len - 1))) != NULL) {
|
||||
|
@ -2302,7 +2302,7 @@ rl_completion_matches(const char *str, rl_compentry_func_t *fun)
|
|||
if ((list[0] = strdup(str)) == NULL)
|
||||
goto out;
|
||||
} else {
|
||||
if ((list[0] = el_malloc((min + 1) * sizeof(*list[0]))) == NULL)
|
||||
if ((list[0] = el_calloc(min + 1, sizeof(*list[0]))) == NULL)
|
||||
goto out;
|
||||
(void)memcpy(list[0], list[1], min);
|
||||
list[0][min] = '\0';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: search.c,v 1.48 2018/02/26 17:36:14 christos Exp $ */
|
||||
/* $NetBSD: search.c,v 1.49 2019/07/23 10:18:52 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: search.c,v 1.48 2018/02/26 17:36:14 christos Exp $");
|
||||
__RCSID("$NetBSD: search.c,v 1.49 2019/07/23 10:18:52 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -70,7 +70,7 @@ libedit_private int
|
|||
search_init(EditLine *el)
|
||||
{
|
||||
|
||||
el->el_search.patbuf = el_malloc(EL_BUFSIZ *
|
||||
el->el_search.patbuf = el_calloc(EL_BUFSIZ,
|
||||
sizeof(*el->el_search.patbuf));
|
||||
if (el->el_search.patbuf == NULL)
|
||||
return -1;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: terminal.c,v 1.38 2019/06/30 13:30:15 christos Exp $ */
|
||||
/* $NetBSD: terminal.c,v 1.39 2019/07/23 10:18:52 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: terminal.c,v 1.38 2019/06/30 13:30:15 christos Exp $");
|
||||
__RCSID("$NetBSD: terminal.c,v 1.39 2019/07/23 10:18:52 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -269,31 +269,27 @@ libedit_private int
|
|||
terminal_init(EditLine *el)
|
||||
{
|
||||
|
||||
el->el_terminal.t_buf = el_malloc(TC_BUFSIZE *
|
||||
el->el_terminal.t_buf = el_calloc(TC_BUFSIZE,
|
||||
sizeof(*el->el_terminal.t_buf));
|
||||
if (el->el_terminal.t_buf == NULL)
|
||||
goto fail1;
|
||||
el->el_terminal.t_cap = el_malloc(TC_BUFSIZE *
|
||||
el->el_terminal.t_cap = el_calloc(TC_BUFSIZE,
|
||||
sizeof(*el->el_terminal.t_cap));
|
||||
if (el->el_terminal.t_cap == NULL)
|
||||
goto fail2;
|
||||
el->el_terminal.t_fkey = el_malloc(A_K_NKEYS *
|
||||
el->el_terminal.t_fkey = el_calloc(A_K_NKEYS,
|
||||
sizeof(*el->el_terminal.t_fkey));
|
||||
if (el->el_terminal.t_fkey == NULL)
|
||||
goto fail3;
|
||||
el->el_terminal.t_loc = 0;
|
||||
el->el_terminal.t_str = el_malloc(T_str *
|
||||
el->el_terminal.t_str = el_calloc(T_str,
|
||||
sizeof(*el->el_terminal.t_str));
|
||||
if (el->el_terminal.t_str == NULL)
|
||||
goto fail4;
|
||||
(void) memset(el->el_terminal.t_str, 0, T_str *
|
||||
sizeof(*el->el_terminal.t_str));
|
||||
el->el_terminal.t_val = el_malloc(T_val *
|
||||
el->el_terminal.t_val = el_calloc(T_val,
|
||||
sizeof(*el->el_terminal.t_val));
|
||||
if (el->el_terminal.t_val == NULL)
|
||||
goto fail5;
|
||||
(void) memset(el->el_terminal.t_val, 0, T_val *
|
||||
sizeof(*el->el_terminal.t_val));
|
||||
(void) terminal_set(el, NULL);
|
||||
terminal_init_arrow(el);
|
||||
return 0;
|
||||
|
@ -426,11 +422,11 @@ terminal_alloc_buffer(EditLine *el)
|
|||
coord_t *c = &el->el_terminal.t_size;
|
||||
int i;
|
||||
|
||||
b = el_malloc(sizeof(*b) * (size_t)(c->v + 1));
|
||||
b = el_calloc((size_t)(c->v + 1), sizeof(*b));
|
||||
if (b == NULL)
|
||||
return NULL;
|
||||
for (i = 0; i < c->v; i++) {
|
||||
b[i] = el_malloc(sizeof(**b) * (size_t)(c->h + 1));
|
||||
b[i] = el_calloc((size_t)(c->h + 1), sizeof(**b));
|
||||
if (b[i] == NULL) {
|
||||
while (--i >= 0)
|
||||
el_free(b[i]);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: vi.c,v 1.62 2016/05/09 21:46:56 christos Exp $ */
|
||||
/* $NetBSD: vi.c,v 1.63 2019/07/23 10:18:52 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: vi.c,v 1.62 2016/05/09 21:46:56 christos Exp $");
|
||||
__RCSID("$NetBSD: vi.c,v 1.63 2019/07/23 10:18:52 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
|
@ -1019,10 +1019,10 @@ vi_histedit(EditLine *el, wint_t c __attribute__((__unused__)))
|
|||
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 * sizeof(*cp));
|
||||
cp = el_calloc(TMP_BUFSIZ, sizeof(*cp));
|
||||
if (cp == NULL)
|
||||
goto error;
|
||||
line = el_malloc(len * sizeof(*line) + 1);
|
||||
line = el_calloc(len + 1, sizeof(*line));
|
||||
if (line == NULL)
|
||||
goto error;
|
||||
wcsncpy(line, el->el_line.buffer, len);
|
||||
|
|
Loading…
Reference in New Issue