Hi tech@
I'm just geting into the OpenBSD source code, and what better way to
learn than with real "work"...
Some malloc/memset to calloc changes. More to come if this kind of work
is appreciated.
Index: answer.c
===================================================================
RCS file: /cvs/src/games/hunt/huntd/answer.c,v
retrieving revision 1.12
diff -u -p -r1.12 answer.c
--- answer.c 23 Mar 2014 02:42:47 -0000 1.12
+++ answer.c 24 May 2014 19:43:20 -0000
@@ -77,13 +77,12 @@ answer_first()
}
/* Remember this spawning connection: */
- sp = (struct spawn *)malloc(sizeof *sp);
+ sp = (struct spawn *)calloc(1, sizeof *sp);
if (sp == NULL) {
logit(LOG_ERR, "malloc");
close(newsock);
return;
}
- memset(sp, '\0', sizeof *sp);
/* Keep the calling machine's source addr for ident purposes: */
memcpy(&sp->source, &sockstruct, sizeof sp->source);
Index: bt_open.c
===================================================================
RCS file: /cvs/src/lib/libc/db/btree/bt_open.c,v
retrieving revision 1.16
diff -u -p -r1.16 bt_open.c
--- bt_open.c 30 Sep 2013 12:02:31 -0000 1.16
+++ bt_open.c 24 May 2014 20:05:02 -0000
@@ -150,9 +150,8 @@ __bt_open(const char *fname, int flags,
goto einval;
/* Allocate and initialize DB and BTREE structures. */
- if ((t = (BTREE *)malloc(sizeof(BTREE))) == NULL)
+ if ((t = (BTREE *)calloc(1, sizeof(BTREE))) == NULL)
goto err;
- memset(t, 0, sizeof(BTREE));
t->bt_fd = -1; /* Don't close unopened fd on
error. */
t->bt_lorder = b.lorder;
t->bt_order = NOT;
Index: auth_subr.c
===================================================================
RCS file: /cvs/src/lib/libc/gen/auth_subr.c,v
retrieving revision 1.39
diff -u -p -r1.39 auth_subr.c
--- auth_subr.c 24 Nov 2013 23:51:29 -0000 1.39
+++ auth_subr.c 24 May 2014 20:14:00 -0000
@@ -167,8 +167,7 @@ auth_open(void)
{
auth_session_t *as;
- if ((as = malloc(sizeof(auth_session_t))) != NULL) {
- memset(as, 0, sizeof(*as));
+ if ((as = calloc(1, sizeof(auth_session_t))) != NULL) {
as->service = defservice;
as->fd = -1;
}
Index: fts.c
===================================================================
RCS file: /cvs/src/lib/libc/gen/fts.c,v
retrieving revision 1.45
diff -u -p -r1.45 fts.c
--- fts.c 30 Sep 2013 12:02:33 -0000 1.45
+++ fts.c 24 May 2014 20:17:02 -0000
@@ -906,10 +906,9 @@ fts_alloc(FTS *sp, char *name, size_t na
len = sizeof(FTSENT) + namelen;
if (!ISSET(FTS_NOSTAT))
len += sizeof(struct stat) + ALIGNBYTES;
- if ((p = malloc(len)) == NULL)
+ if ((p = calloc(1, len)) == NULL)
return (NULL);
- memset(p, 0, len);
p->fts_path = sp->fts_path;
p->fts_namelen = namelen;
p->fts_instr = FTS_NOINSTR;
Index: rune.c
===================================================================
RCS file: /cvs/src/lib/libc/locale/rune.c,v
retrieving revision 1.3
diff -u -p -r1.3 rune.c
--- rune.c 5 Dec 2012 23:20:00 -0000 1.3
+++ rune.c 24 May 2014 20:22:49 -0000
@@ -230,9 +230,8 @@ _Read_RuneMagi(FILE *fp)
ntohl(frl.frl_maplower_ext.frr_nranges) * sizeof(_RuneEntry) +
ntohl(frl.frl_mapupper_ext.frr_nranges) * sizeof(_RuneEntry);
- if ((hostdata = malloc(hostdatalen)) == NULL)
+ if ((hostdata = calloc(1, hostdatalen)) == NULL)
return NULL;
- memset(hostdata, 0, hostdatalen);
lastp = hostdata + hostdatalen;
rl = (_RuneLocale *)hostdata;
Index: yp_bind.c
===================================================================
RCS file: /cvs/src/lib/libc/yp/yp_bind.c,v
retrieving revision 1.19
diff -u -p -r1.19 yp_bind.c
--- yp_bind.c 30 Sep 2013 12:02:36 -0000 1.19
+++ yp_bind.c 24 May 2014 20:27:27 -0000
@@ -97,9 +97,8 @@ _yp_dobind(const char *dom, struct dom_b
if (strcmp(dom, ysd->dom_domain) == 0)
break;
if (ysd == NULL) {
- if ((ysd = malloc(sizeof *ysd)) == NULL)
+ if ((ysd = calloc(1, sizeof *ysd)) == NULL)
return YPERR_RESRC;
- (void)memset(ysd, 0, sizeof *ysd);
ysd->dom_socket = -1;
ysd->dom_vers = 0;
new = 1;
Index: fts1.c
===================================================================
RCS file: /cvs/src/lib/libsqlite3/ext/fts1/fts1.c,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 fts1.c
--- fts1.c 21 Sep 2013 17:29:18 -0000 1.1.1.2
+++ fts1.c 24 May 2014 20:56:05 -0000
@@ -1945,9 +1945,8 @@ static int constructVtab(
const sqlite3_tokenizer_module *m = NULL;
char *schema;
- v = (fulltext_vtab *) malloc(sizeof(fulltext_vtab));
+ v = (fulltext_vtab *) calloc(1, sizeof(fulltext_vtab));
if( v==0 ) return SQLITE_NOMEM;
- memset(v, 0, sizeof(*v));
/* sqlite will initialize v->base */
v->db = db;
v->zDb = spec->zDb; /* Freed when azColumn is freed */
Index: bn_blind.c
===================================================================
RCS file: /cvs/src/lib/libssl/src/crypto/bn/bn_blind.c,v
retrieving revision 1.9
diff -u -p -r1.9 bn_blind.c
--- bn_blind.c 8 May 2014 13:20:49 -0000 1.9
+++ bn_blind.c 24 May 2014 21:09:40 -0000
@@ -139,11 +139,10 @@ BN_BLINDING_new(const BIGNUM *A, const B
bn_check_top(mod);
- if ((ret = (BN_BLINDING *)malloc(sizeof(BN_BLINDING))) == NULL) {
+ if ((ret = (BN_BLINDING *)calloc(1, sizeof(BN_BLINDING))) == NULL) {
BNerr(BN_F_BN_BLINDING_NEW, ERR_R_MALLOC_FAILURE);
return (NULL);
}
- memset(ret, 0, sizeof(BN_BLINDING));
if (A != NULL) {
if ((ret->A = BN_dup(A)) == NULL)
goto err;
Index: comp_lib.c
===================================================================
RCS file: /cvs/src/lib/libssl/src/crypto/comp/comp_lib.c,v
retrieving revision 1.5
diff -u -p -r1.5 comp_lib.c
--- comp_lib.c 26 Apr 2014 13:04:24 -0000 1.5
+++ comp_lib.c 24 May 2014 21:12:44 -0000
@@ -9,11 +9,10 @@ COMP_CTX_new(COMP_METHOD *meth)
{
COMP_CTX *ret;
- if ((ret = (COMP_CTX *)malloc(sizeof(COMP_CTX))) == NULL) {
+ if ((ret = (COMP_CTX *)calloc(1, sizeof(COMP_CTX))) == NULL) {
/* ZZZZZZZZZZZZZZZZ */
return (NULL);
}
- memset(ret, 0, sizeof(COMP_CTX));
ret->meth = meth;
if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
free(ret);
Index: ecp_nistp224.c
===================================================================
RCS file: /cvs/src/lib/libssl/src/crypto/ec/ecp_nistp224.c,v
retrieving revision 1.7
diff -u -p -r1.7 ecp_nistp224.c
--- ecp_nistp224.c 15 May 2014 11:25:59 -0000 1.7
+++ ecp_nistp224.c 24 May 2014 21:23:08 -0000
@@ -1435,8 +1435,8 @@ ec_GFp_nistp224_points_mul(const EC_GROU
*/
mixed = 1;
}
- secrets = malloc(num_points * sizeof(felem_bytearray));
- pre_comp = malloc(num_points * 17 * 3 * sizeof(felem));
+ secrets = calloc(num_points, sizeof(felem_bytearray));
+ pre_comp = calloc(num_points * 17 * 3, sizeof(felem));
if (mixed)
tmp_felems = malloc((num_points * 17 + 1) *
sizeof(felem));
if ((secrets == NULL) || (pre_comp == NULL) || (mixed && (tmp_felems
== NULL))) {
@@ -1448,8 +1448,6 @@ ec_GFp_nistp224_points_mul(const EC_GROU
* infinity, i.e., they contribute nothing to the linear
* combination
*/
- memset(secrets, 0, num_points * sizeof(felem_bytearray));
- memset(pre_comp, 0, num_points * 17 * 3 * sizeof(felem));
for (i = 0; i < num_points; ++i) {
if (i == num)
/* the generator */
Index: ecp_nistp256.c
===================================================================
RCS file: /cvs/src/lib/libssl/src/crypto/ec/ecp_nistp256.c,v
retrieving revision 1.7
diff -u -p -r1.7 ecp_nistp256.c
--- ecp_nistp256.c 15 May 2014 11:25:59 -0000 1.7
+++ ecp_nistp256.c 24 May 2014 21:26:35 -0000
@@ -1985,8 +1985,8 @@ ec_GFp_nistp256_points_mul(const EC_GROU
*/
mixed = 1;
}
- secrets = malloc(num_points * sizeof(felem_bytearray));
- pre_comp = malloc(num_points * 17 * 3 * sizeof(smallfelem));
+ secrets = calloc(num_points, sizeof(felem_bytearray));
+ pre_comp = calloc(num_points * 17 * 3, sizeof(smallfelem));
if (mixed)
tmp_smallfelems = malloc((num_points * 17 + 1) *
sizeof(smallfelem));
if ((secrets == NULL) || (pre_comp == NULL) || (mixed &&
(tmp_smallfelems == NULL))) {
@@ -1998,8 +1998,6 @@ ec_GFp_nistp256_points_mul(const EC_GROU
* infinity, i.e., they contribute nothing to the linear
* combination
*/
- memset(secrets, 0, num_points * sizeof(felem_bytearray));
- memset(pre_comp, 0, num_points * 17 * 3 * sizeof(smallfelem));
for (i = 0; i < num_points; ++i) {
if (i == num)
/*
Index: ecp_nistp521.c
===================================================================
RCS file: /cvs/src/lib/libssl/src/crypto/ec/ecp_nistp521.c,v
retrieving revision 1.8
diff -u -p -r1.8 ecp_nistp521.c
--- ecp_nistp521.c 15 May 2014 11:25:59 -0000 1.8
+++ ecp_nistp521.c 24 May 2014 21:28:16 -0000
@@ -1872,8 +1872,8 @@ ec_GFp_nistp521_points_mul(const EC_GROU
*/
mixed = 1;
}
- secrets = malloc(num_points * sizeof(felem_bytearray));
- pre_comp = malloc(num_points * 17 * 3 * sizeof(felem));
+ secrets = calloc(num_points, sizeof(felem_bytearray));
+ pre_comp = calloc(num_points * 17 * 3, sizeof(felem));
if (mixed)
tmp_felems = malloc((num_points * 17 + 1) *
sizeof(felem));
if ((secrets == NULL) || (pre_comp == NULL) || (mixed && (tmp_felems
== NULL))) {
@@ -1885,8 +1885,6 @@ ec_GFp_nistp521_points_mul(const EC_GROU
* infinity, i.e., they contribute nothing to the linear
* combination
*/
- memset(secrets, 0, num_points * sizeof(felem_bytearray));
- memset(pre_comp, 0, num_points * 17 * 3 * sizeof(felem));
for (i = 0; i < num_points; ++i) {
if (i == num)
/*
Index: pmeth_lib.c
===================================================================
RCS file: /cvs/src/lib/libssl/src/crypto/evp/pmeth_lib.c,v
retrieving revision 1.3
diff -u -p -r1.3 pmeth_lib.c
--- pmeth_lib.c 7 May 2014 17:42:51 -0000 1.3
+++ pmeth_lib.c 24 May 2014 21:30:17 -0000
@@ -196,11 +196,9 @@ EVP_PKEY_meth_new(int id, int flags)
{
EVP_PKEY_METHOD *pmeth;
- pmeth = malloc(sizeof(EVP_PKEY_METHOD));
+ pmeth = calloc(1, sizeof(EVP_PKEY_METHOD));
if (!pmeth)
return NULL;
-
- memset(pmeth, 0, sizeof(EVP_PKEY_METHOD));
pmeth->pkey_id = id;
pmeth->flags = flags | EVP_PKEY_FLAG_DYNAMIC;
Index: bio_ber.c
===================================================================
RCS file: /cvs/src/lib/libssl/src/crypto/pkcs7/bio_ber.c,v
retrieving revision 1.9
diff -u -p -r1.9 bio_ber.c
--- bio_ber.c 27 Apr 2014 20:26:49 -0000 1.9
+++ bio_ber.c 24 May 2014 21:32:22 -0000
@@ -126,10 +126,8 @@ static int ber_new(BIO *bi)
{
BIO_BER_CTX *ctx;
- ctx=(BIO_BER_CTX *)malloc(sizeof(BIO_BER_CTX));
+ ctx=(BIO_BER_CTX *)calloc(1, sizeof(BIO_BER_CTX));
if (ctx == NULL) return(0);
-
- memset((char *)ctx,0,sizeof(BIO_BER_CTX));
bi->init=0;
bi->ptr=(char *)ctx;