aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog20
-rw-r--r--awkgram.c9
-rw-r--r--awkgram.y9
-rw-r--r--cint_array.c18
-rw-r--r--command.c3
-rw-r--r--command.y3
-rw-r--r--debug.c3
-rw-r--r--eval.c3
-rw-r--r--extension/ChangeLog8
-rw-r--r--extension/filefuncs.c3
-rw-r--r--extension/gawkfts.c3
-rw-r--r--extension/readfile.c3
-rw-r--r--extension/rwarray.c3
-rw-r--r--extension/rwarray0.c3
-rw-r--r--field.c4
-rw-r--r--gawkapi.c3
-rw-r--r--int_array.c6
-rw-r--r--io.c6
-rw-r--r--missing_d/ChangeLog4
-rw-r--r--missing_d/getaddrinfo.c3
-rw-r--r--node.c3
-rw-r--r--old-extension/ChangeLog4
-rw-r--r--old-extension/bindarr.c3
-rw-r--r--re.c3
-rw-r--r--str_array.c6
-rw-r--r--symbol.c6
26 files changed, 71 insertions, 71 deletions
diff --git a/ChangeLog b/ChangeLog
index 233ec4bd..fe8e49b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2017-06-21 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ Replace malloc/memset combinations with calloc by using the new ezalloc
+ macro.
+ * awkgram.y (yyerror, do_add_srcfile, funcuse): Replace emalloc+memset
+ with ezalloc.
+ * cint_array.c (cint_lookup, cint_copy, tree_lookup, tree_copy,
+ leaf_lookup, leaf_copy): Ditto.
+ * command.y (mk_cmdarg): Ditto.
+ * debug.c (add_item): Ditto.
+ * eval.c (setup_frame): Ditto.
+ * field.c (set_record): Ditto.
+ * gawkapi.c (api_flatten_array_typed): Ditto.
+ * int_array.c (int_copy, grow_int_table): Ditto.
+ * io.c (init_awkpath, iop_alloc): Ditto.
+ * node.c (str2wstr): Ditto.
+ * re.c (make_regexp): Ditto.
+ * str_array.c (str_copy, grow_table): Ditto.
+ * symbol.c (make_params, new_context): Ditto.
+
2017-06-19 Andrew J. Schorr <aschorr@telemetry-investments.com>
* awk.h (ezalloc): Add new macro to allocate memory initialized to zero.
diff --git a/awkgram.c b/awkgram.c
index 4325e77d..28845c61 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -4813,8 +4813,7 @@ yyerror(const char *m, ...)
count = strlen(mesg) + 1;
if (lexptr != NULL)
count += (lexeme - thisline) + 2;
- emalloc(buf, char *, count+1, "yyerror");
- memset(buf, 0, count+1);
+ ezalloc(buf, char *, count+1, "yyerror");
bp = buf;
@@ -5033,8 +5032,7 @@ do_add_srcfile(enum srctype stype, char *src, char *path, SRCFILE *thisfile)
{
SRCFILE *s;
- emalloc(s, SRCFILE *, sizeof(SRCFILE), "do_add_srcfile");
- memset(s, 0, sizeof(SRCFILE));
+ ezalloc(s, SRCFILE *, sizeof(SRCFILE), "do_add_srcfile");
s->src = estrdup(src, strlen(src));
s->fullpath = path;
s->stype = stype;
@@ -7313,8 +7311,7 @@ func_use(const char *name, enum defref how)
/* not in the table, fall through to allocate a new one */
- emalloc(fp, struct fdesc *, sizeof(struct fdesc), "func_use");
- memset(fp, '\0', sizeof(struct fdesc));
+ ezalloc(fp, struct fdesc *, sizeof(struct fdesc), "func_use");
emalloc(fp->name, char *, len + 1, "func_use");
strcpy(fp->name, name);
fp->next = ftable[ind];
diff --git a/awkgram.y b/awkgram.y
index e4f5bab0..ad6873bb 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -2393,8 +2393,7 @@ yyerror(const char *m, ...)
count = strlen(mesg) + 1;
if (lexptr != NULL)
count += (lexeme - thisline) + 2;
- emalloc(buf, char *, count+1, "yyerror");
- memset(buf, 0, count+1);
+ ezalloc(buf, char *, count+1, "yyerror");
bp = buf;
@@ -2613,8 +2612,7 @@ do_add_srcfile(enum srctype stype, char *src, char *path, SRCFILE *thisfile)
{
SRCFILE *s;
- emalloc(s, SRCFILE *, sizeof(SRCFILE), "do_add_srcfile");
- memset(s, 0, sizeof(SRCFILE));
+ ezalloc(s, SRCFILE *, sizeof(SRCFILE), "do_add_srcfile");
s->src = estrdup(src, strlen(src));
s->fullpath = path;
s->stype = stype;
@@ -4893,8 +4891,7 @@ func_use(const char *name, enum defref how)
/* not in the table, fall through to allocate a new one */
- emalloc(fp, struct fdesc *, sizeof(struct fdesc), "func_use");
- memset(fp, '\0', sizeof(struct fdesc));
+ ezalloc(fp, struct fdesc *, sizeof(struct fdesc), "func_use");
emalloc(fp->name, char *, len + 1, "func_use");
strcpy(fp->name, name);
fp->next = ftable[ind];
diff --git a/cint_array.c b/cint_array.c
index 092ce88a..851e980e 100644
--- a/cint_array.c
+++ b/cint_array.c
@@ -228,8 +228,7 @@ cint_lookup(NODE *symbol, NODE *subs)
assert(symbol->table_size == 0);
/* nodes[0] .. nodes[NHAT- 1] not used */
- emalloc(symbol->nodes, NODE **, INT32_BIT * sizeof(NODE *), "cint_lookup");
- memset(symbol->nodes, '\0', INT32_BIT * sizeof(NODE *));
+ ezalloc(symbol->nodes, NODE **, INT32_BIT * sizeof(NODE *), "cint_lookup");
}
symbol->table_size++; /* one more element in array */
@@ -387,8 +386,7 @@ cint_copy(NODE *symbol, NODE *newsymb)
assert(symbol->nodes != NULL);
/* allocate new table */
- emalloc(new, NODE **, INT32_BIT * sizeof(NODE *), "cint_copy");
- memset(new, '\0', INT32_BIT * sizeof(NODE *));
+ ezalloc(new, NODE **, INT32_BIT * sizeof(NODE *), "cint_copy");
old = symbol->nodes;
for (i = NHAT; i < INT32_BIT; i++) {
@@ -754,8 +752,7 @@ tree_lookup(NODE *symbol, NODE *tree, long k, int m, long base)
actual_size /= 2;
tree->flags |= HALFHAT;
}
- emalloc(table, NODE **, actual_size * sizeof(NODE *), "tree_lookup");
- memset(table, '\0', actual_size * sizeof(NODE *));
+ ezalloc(table, NODE **, actual_size * sizeof(NODE *), "tree_lookup");
tree->nodes = table;
} else
size = tree->array_size;
@@ -928,8 +925,7 @@ tree_copy(NODE *newsymb, NODE *tree, NODE *newtree)
if ((tree->flags & HALFHAT) != 0)
hsize /= 2;
- emalloc(new, NODE **, hsize * sizeof(NODE *), "tree_copy");
- memset(new, '\0', hsize * sizeof(NODE *));
+ ezalloc(new, NODE **, hsize * sizeof(NODE *), "tree_copy");
newtree->nodes = new;
newtree->array_base = tree->array_base;
newtree->array_size = tree->array_size;
@@ -1047,8 +1043,7 @@ leaf_lookup(NODE *symbol, NODE *array, long k, long size, long base)
array->table_size = 0; /* sanity */
array->array_size = size;
array->array_base = base;
- emalloc(array->nodes, NODE **, size * sizeof(NODE *), "leaf_lookup");
- memset(array->nodes, '\0', size * sizeof(NODE *));
+ ezalloc(array->nodes, NODE **, size * sizeof(NODE *), "leaf_lookup");
symbol->array_capacity += size;
}
@@ -1127,8 +1122,7 @@ leaf_copy(NODE *newsymb, NODE *array, NODE *newarray)
long size, i;
size = array->array_size;
- emalloc(new, NODE **, size * sizeof(NODE *), "leaf_copy");
- memset(new, '\0', size * sizeof(NODE *));
+ ezalloc(new, NODE **, size * sizeof(NODE *), "leaf_copy");
newarray->nodes = new;
newarray->array_size = size;
newarray->array_base = array->array_base;
diff --git a/command.c b/command.c
index a0469bb8..1d804c75 100644
--- a/command.c
+++ b/command.c
@@ -2707,8 +2707,7 @@ static CMDARG *
mk_cmdarg(enum argtype type)
{
CMDARG *arg;
- emalloc(arg, CMDARG *, sizeof(CMDARG), "mk_cmdarg");
- memset(arg, 0, sizeof(CMDARG));
+ ezalloc(arg, CMDARG *, sizeof(CMDARG), "mk_cmdarg");
arg->type = type;
return arg;
}
diff --git a/command.y b/command.y
index 4597dba1..65d21853 100644
--- a/command.y
+++ b/command.y
@@ -957,8 +957,7 @@ static CMDARG *
mk_cmdarg(enum argtype type)
{
CMDARG *arg;
- emalloc(arg, CMDARG *, sizeof(CMDARG), "mk_cmdarg");
- memset(arg, 0, sizeof(CMDARG));
+ ezalloc(arg, CMDARG *, sizeof(CMDARG), "mk_cmdarg");
arg->type = type;
return arg;
}
diff --git a/debug.c b/debug.c
index fc0f94cd..c3bc3009 100644
--- a/debug.c
+++ b/debug.c
@@ -1371,8 +1371,7 @@ add_item(struct list_item *list, int type, NODE *symbol, char *pname)
{
struct list_item *d;
- emalloc(d, struct list_item *, sizeof(struct list_item), "add_item");
- memset(d, 0, sizeof(struct list_item));
+ ezalloc(d, struct list_item *, sizeof(struct list_item), "add_item");
d->commands.next = d->commands.prev = &d->commands;
d->number = ++list->number;
diff --git a/eval.c b/eval.c
index 73bd7fc9..c5fea5ee 100644
--- a/eval.c
+++ b/eval.c
@@ -1269,8 +1269,7 @@ setup_frame(INSTRUCTION *pc)
sp = frame_ptr->stack;
} else if (pcount > 0) {
- emalloc(sp, NODE **, pcount * sizeof(NODE *), "setup_frame");
- memset(sp, 0, pcount * sizeof(NODE *));
+ ezalloc(sp, NODE **, pcount * sizeof(NODE *), "setup_frame");
}
diff --git a/extension/ChangeLog b/extension/ChangeLog
index d10dc766..378de373 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,3 +1,11 @@
+2017-06-21 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * filefuncs.c (do_fts): Replace emalloc+memset with ezalloc.
+ * readfile.c (read_file_to_buffer): Ditto.
+ * rwarray.c (read_value): Replace gawk_malloc+memset with gawk_calloc.
+ * gawkfts.c (fts_open): Replace malloc+memset with calloc.
+ * rwarray0.c (read_value): Ditto.
+
2017-04-03 Arnold D. Robbins <arnold@skeeve.com>
* inplace.c (inplace_end): Correct the function name in the
diff --git a/extension/filefuncs.c b/extension/filefuncs.c
index 394de504..9ca22de8 100644
--- a/extension/filefuncs.c
+++ b/extension/filefuncs.c
@@ -877,8 +877,7 @@ do_fts(int nargs, awk_value_t *result, struct awk_ext_func *unused)
/* make pathvector */
count = path_array->count + 1;
- emalloc(pathvector, char **, count * sizeof(char *), "do_fts");
- memset(pathvector, 0, count * sizeof(char *));
+ ezalloc(pathvector, char **, count * sizeof(char *), "do_fts");
/* fill it in */
count--; /* ignore final NULL at end of vector */
diff --git a/extension/gawkfts.c b/extension/gawkfts.c
index 4a712153..d9edd87f 100644
--- a/extension/gawkfts.c
+++ b/extension/gawkfts.c
@@ -162,9 +162,8 @@ fts_open(char * const *argv, int options,
}
/* Allocate/initialize the stream */
- if ((sp = malloc((unsigned int)sizeof(FTS))) == NULL)
+ if ((sp = calloc(1, (unsigned int)sizeof(FTS))) == NULL)
return (NULL);
- memset(sp, 0, sizeof(FTS));
sp->fts_compar = compar;
sp->fts_options = options;
diff --git a/extension/readfile.c b/extension/readfile.c
index fb1a376b..f470237b 100644
--- a/extension/readfile.c
+++ b/extension/readfile.c
@@ -82,8 +82,7 @@ read_file_to_buffer(int fd, const struct stat *sbuf)
goto done;
}
- emalloc(text, char *, sbuf->st_size + 1, "do_readfile");
- memset(text, '\0', sbuf->st_size + 1);
+ ezalloc(text, char *, sbuf->st_size + 1, "do_readfile");
if ((ret = read(fd, text, sbuf->st_size)) != sbuf->st_size) {
update_ERRNO_int(errno);
diff --git a/extension/rwarray.c b/extension/rwarray.c
index a7d752cf..370e38ac 100644
--- a/extension/rwarray.c
+++ b/extension/rwarray.c
@@ -482,8 +482,7 @@ read_value(FILE *fp, awk_value_t *value)
break;
}
value->str_value.len = len;
- value->str_value.str = gawk_malloc(len + 1);
- memset(value->str_value.str, '\0', len + 1);
+ value->str_value.str = gawk_calloc(1, len + 1);
if (fread(value->str_value.str, 1, len, fp) != (ssize_t) len) {
gawk_free(value->str_value.str);
diff --git a/extension/rwarray0.c b/extension/rwarray0.c
index faa73783..abeb5326 100644
--- a/extension/rwarray0.c
+++ b/extension/rwarray0.c
@@ -446,8 +446,7 @@ read_value(int fd, awk_value_t *value)
len = ntohl(len);
value->val_type = AWK_STRING;
value->str_value.len = len;
- value->str_value.str = malloc(len + 1);
- memset(value->str_value.str, '\0', len + 1);
+ value->str_value.str = calloc(1, len + 1);
if (read(fd, value->str_value.str, len) != (ssize_t) len) {
free(value->str_value.str);
diff --git a/field.c b/field.c
index 61f0d7f6..d8c97413 100644
--- a/field.c
+++ b/field.c
@@ -274,10 +274,8 @@ set_record(const char *buf, int cnt, const awk_fieldwidth_info_t *fw)
/* buffer management: */
if (databuf_size == 0) { /* first time */
- emalloc(databuf, char *, INITIAL_SIZE, "set_record");
+ ezalloc(databuf, char *, INITIAL_SIZE, "set_record");
databuf_size = INITIAL_SIZE;
- memset(databuf, '\0', INITIAL_SIZE);
-
}
/*
* Make sure there's enough room. Since we sometimes need
diff --git a/gawkapi.c b/gawkapi.c
index 4c6a2f8f..fcdfe0dc 100644
--- a/gawkapi.c
+++ b/gawkapi.c
@@ -1111,9 +1111,8 @@ api_flatten_array_typed(awk_ext_id_t id,
alloc_size = sizeof(awk_flat_array_t) +
(array->table_size - 1) * sizeof(awk_element_t);
- emalloc(*data, awk_flat_array_t *, alloc_size,
+ ezalloc(*data, awk_flat_array_t *, alloc_size,
"api_flatten_array_typed");
- memset(*data, 0, alloc_size);
list = assoc_list(array, "@unsorted", ASORTI);
diff --git a/int_array.c b/int_array.c
index 992da4a6..1c309cfd 100644
--- a/int_array.c
+++ b/int_array.c
@@ -458,8 +458,7 @@ int_copy(NODE *symbol, NODE *newsymb)
cursize = symbol->array_size;
/* allocate new table */
- emalloc(new, BUCKET **, cursize * sizeof(BUCKET *), "int_copy");
- memset(new, '\0', cursize * sizeof(BUCKET *));
+ ezalloc(new, BUCKET **, cursize * sizeof(BUCKET *), "int_copy");
old = symbol->buckets;
@@ -842,8 +841,7 @@ grow_int_table(NODE *symbol)
}
/* allocate new table */
- emalloc(new, BUCKET **, newsize * sizeof(BUCKET *), "grow_int_table");
- memset(new, '\0', newsize * sizeof(BUCKET *));
+ ezalloc(new, BUCKET **, newsize * sizeof(BUCKET *), "grow_int_table");
old = symbol->buckets;
symbol->buckets = new;
diff --git a/io.c b/io.c
index e08c3373..5d79e170 100644
--- a/io.c
+++ b/io.c
@@ -2803,8 +2803,7 @@ init_awkpath(path_info *pi)
max_path++;
// +3 --> 2 for null entries at front and end of path, 1 for NULL end of list
- emalloc(pi->awkpath, char **, (max_path + 3) * sizeof(char *), "init_awkpath");
- memset(pi->awkpath, 0, (max_path + 3) * sizeof(char *));
+ ezalloc(pi->awkpath, char **, (max_path + 3) * sizeof(char *), "init_awkpath");
start = path;
i = 0;
@@ -3211,9 +3210,8 @@ iop_alloc(int fd, const char *name, int errno_val)
{
IOBUF *iop;
- emalloc(iop, IOBUF *, sizeof(IOBUF), "iop_alloc");
+ ezalloc(iop, IOBUF *, sizeof(IOBUF), "iop_alloc");
- memset(iop, '\0', sizeof(IOBUF));
iop->public.fd = fd;
iop->public.name = name;
iop->public.read_func = ( ssize_t(*)() ) read;
diff --git a/missing_d/ChangeLog b/missing_d/ChangeLog
index 83f5b93e..7d9bddc4 100644
--- a/missing_d/ChangeLog
+++ b/missing_d/ChangeLog
@@ -1,3 +1,7 @@
+2017-06-21 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * getaddrinfo.c (getaddrinfo): Replace malloc+memset with calloc.
+
2016-10-23 Arnold D. Robbins <arnold@skeeve.com>
* General: Remove trailing whitespace from all relevant files.
diff --git a/missing_d/getaddrinfo.c b/missing_d/getaddrinfo.c
index f24ac598..5233cf56 100644
--- a/missing_d/getaddrinfo.c
+++ b/missing_d/getaddrinfo.c
@@ -33,12 +33,11 @@ getaddrinfo(const char *hostname, const char *portname,
if (res == NULL)
return EINVAL;
- out = (struct addrinfo *) malloc(sizeof(*out));
+ out = (struct addrinfo *) calloc(1, sizeof(*out));
if (out == NULL) {
*res = NULL;
return ENOMEM;
}
- memset(out, '\0', sizeof(*out));
out->ai_addr = (struct sockaddr *) malloc(sizeof(struct sockaddr_in));
if (out->ai_addr == NULL) {
diff --git a/node.c b/node.c
index 962a650d..200d61dc 100644
--- a/node.c
+++ b/node.c
@@ -728,8 +728,7 @@ str2wstr(NODE *n, size_t **ptr)
* Create the array.
*/
if (ptr != NULL) {
- emalloc(*ptr, size_t *, sizeof(size_t) * n->stlen, "str2wstr");
- memset(*ptr, 0, sizeof(size_t) * n->stlen);
+ ezalloc(*ptr, size_t *, sizeof(size_t) * n->stlen, "str2wstr");
}
sp = n->stptr;
diff --git a/old-extension/ChangeLog b/old-extension/ChangeLog
index bd848f9a..99352c6e 100644
--- a/old-extension/ChangeLog
+++ b/old-extension/ChangeLog
@@ -1,3 +1,7 @@
+2017-06-21 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * bindarr.c (do_bind_array): Replace emalloc+memset with ezalloc.
+
2016-10-23 Arnold D. Robbins <arnold@skeeve.com>
* General: Remove trailing whitespace from all relevant files.
diff --git a/old-extension/bindarr.c b/old-extension/bindarr.c
index 1a0104db..34e7e983 100644
--- a/old-extension/bindarr.c
+++ b/old-extension/bindarr.c
@@ -209,8 +209,7 @@ do_bind_array(int nargs)
assoc_clear(symbol);
- emalloc(aq, array_t *, sizeof(array_t), "do_bind_array");
- memset(aq, '\0', sizeof(array_t));
+ ezalloc(aq, array_t *, sizeof(array_t), "do_bind_array");
t = get_array_argument(1, false);
diff --git a/re.c b/re.c
index 73e75cbb..cf369a97 100644
--- a/re.c
+++ b/re.c
@@ -168,8 +168,7 @@ make_regexp(const char *s, size_t len, bool ignorecase, bool dfa, bool canfatal)
*dest = '\0';
len = dest - buf;
- emalloc(rp, Regexp *, sizeof(*rp), "make_regexp");
- memset((char *) rp, 0, sizeof(*rp));
+ ezalloc(rp, Regexp *, sizeof(*rp), "make_regexp");
rp->pat.allocated = 0; /* regex will allocate the buffer */
emalloc(rp->pat.fastmap, char *, 256, "make_regexp");
diff --git a/str_array.c b/str_array.c
index fe07ce4b..0f75b300 100644
--- a/str_array.c
+++ b/str_array.c
@@ -325,8 +325,7 @@ str_copy(NODE *symbol, NODE *newsymb)
cursize = symbol->array_size;
/* allocate new table */
- emalloc(new, BUCKET **, cursize * sizeof(BUCKET *), "str_copy");
- memset(new, '\0', cursize * sizeof(BUCKET *));
+ ezalloc(new, BUCKET **, cursize * sizeof(BUCKET *), "str_copy");
old = symbol->buckets;
@@ -666,8 +665,7 @@ grow_table(NODE *symbol)
}
/* allocate new table */
- emalloc(new, BUCKET **, newsize * sizeof(BUCKET *), "grow_table");
- memset(new, '\0', newsize * sizeof(BUCKET *));
+ ezalloc(new, BUCKET **, newsize * sizeof(BUCKET *), "grow_table");
old = symbol->buckets;
symbol->buckets = new;
diff --git a/symbol.c b/symbol.c
index ea5ee0af..cbbd8ed2 100644
--- a/symbol.c
+++ b/symbol.c
@@ -133,8 +133,7 @@ make_params(char **pnames, int pcount)
if (pcount <= 0 || pnames == NULL)
return NULL;
- emalloc(parms, NODE *, pcount * sizeof(NODE), "make_params");
- memset(parms, '\0', pcount * sizeof(NODE));
+ ezalloc(parms, NODE *, pcount * sizeof(NODE), "make_params");
for (i = 0, p = parms; i < pcount; i++, p++) {
p->type = Node_param_list;
@@ -759,8 +758,7 @@ new_context()
{
AWK_CONTEXT *ctxt;
- emalloc(ctxt, AWK_CONTEXT *, sizeof(AWK_CONTEXT), "new_context");
- memset(ctxt, 0, sizeof(AWK_CONTEXT));
+ ezalloc(ctxt, AWK_CONTEXT *, sizeof(AWK_CONTEXT), "new_context");
ctxt->srcfiles.next = ctxt->srcfiles.prev = & ctxt->srcfiles;
ctxt->rule_list.opcode = Op_list;
ctxt->rule_list.lasti = & ctxt->rule_list;