summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-08-13 10:36:06 -0400
committerNick Mathewson <nickm@torproject.org>2014-08-13 10:39:56 -0400
commit2bfd92d0d170642fb12f53e5da208f318fdd632c (patch)
tree09da23f22e58e196fef9995e21b59aff3b555487 /src/common
parent5da821a8a3cfffc18f5a656852d98e69cff5dd8f (diff)
downloadtor-2bfd92d0d170642fb12f53e5da208f318fdd632c.tar.gz
tor-2bfd92d0d170642fb12f53e5da208f318fdd632c.zip
Apply coccinelle script to replace malloc(a*b)->calloc(a,b)
Diffstat (limited to 'src/common')
-rw-r--r--src/common/compat.c4
-rw-r--r--src/common/container.c5
-rw-r--r--src/common/container.h4
-rw-r--r--src/common/crypto.c4
-rw-r--r--src/common/util.c6
5 files changed, 12 insertions, 11 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index dcdf78d49f..c4f5987d5a 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -1687,12 +1687,12 @@ log_credential_status(void)
/* log supplementary groups */
sup_gids_size = 64;
- sup_gids = tor_malloc(sizeof(gid_t) * 64);
+ sup_gids = tor_calloc(sizeof(gid_t), 64);
while ((ngids = getgroups(sup_gids_size, sup_gids)) < 0 &&
errno == EINVAL &&
sup_gids_size < NGROUPS_MAX) {
sup_gids_size *= 2;
- sup_gids = tor_realloc(sup_gids, sizeof(gid_t) * sup_gids_size);
+ sup_gids = tor_reallocarray(sup_gids, sizeof(gid_t), sup_gids_size);
}
if (ngids < 0) {
diff --git a/src/common/container.c b/src/common/container.c
index b937d544fc..9bbb9730c6 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -34,7 +34,7 @@ smartlist_new(void)
smartlist_t *sl = tor_malloc(sizeof(smartlist_t));
sl->num_used = 0;
sl->capacity = SMARTLIST_DEFAULT_CAPACITY;
- sl->list = tor_malloc(sizeof(void *) * sl->capacity);
+ sl->list = tor_calloc(sizeof(void *), sl->capacity);
return sl;
}
@@ -77,7 +77,8 @@ smartlist_ensure_capacity(smartlist_t *sl, int size)
higher *= 2;
}
sl->capacity = higher;
- sl->list = tor_realloc(sl->list, sizeof(void*)*((size_t)sl->capacity));
+ sl->list = tor_reallocarray(sl->list, sizeof(void *),
+ ((size_t)sl->capacity));
}
}
diff --git a/src/common/container.h b/src/common/container.h
index 0d31f2093b..08da34e07e 100644
--- a/src/common/container.h
+++ b/src/common/container.h
@@ -563,7 +563,7 @@ bitarray_init_zero(unsigned int n_bits)
{
/* round up to the next int. */
size_t sz = (n_bits+BITARRAY_MASK) >> BITARRAY_SHIFT;
- return tor_malloc_zero(sz*sizeof(unsigned int));
+ return tor_calloc(sz, sizeof(unsigned int));
}
/** Expand <b>ba</b> from holding <b>n_bits_old</b> to <b>n_bits_new</b>,
* clearing all new bits. Returns a possibly changed pointer to the
@@ -577,7 +577,7 @@ bitarray_expand(bitarray_t *ba,
char *ptr;
if (sz_new <= sz_old)
return ba;
- ptr = tor_realloc(ba, sz_new*sizeof(unsigned int));
+ ptr = tor_reallocarray(ba, sz_new, sizeof(unsigned int));
/* This memset does nothing to the older excess bytes. But they were
* already set to 0 by bitarry_init_zero. */
memset(ptr+sz_old*sizeof(unsigned int), 0,
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 16292455b5..014c83e850 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -1838,7 +1838,7 @@ crypto_store_dynamic_dh_modulus(const char *fname)
goto done;
}
- base64_encoded_dh = tor_malloc_zero(len * 2); /* should be enough */
+ base64_encoded_dh = tor_calloc(len, 2); /* should be enough */
new_len = base64_encode(base64_encoded_dh, len * 2,
(char *)dh_string_repr, len);
if (new_len < 0) {
@@ -3164,7 +3164,7 @@ setup_openssl_threading(void)
int i;
int n = CRYPTO_num_locks();
n_openssl_mutexes_ = n;
- openssl_mutexes_ = tor_malloc(n*sizeof(tor_mutex_t *));
+ openssl_mutexes_ = tor_calloc(n, sizeof(tor_mutex_t *));
for (i=0; i < n; ++i)
openssl_mutexes_[i] = tor_mutex_new();
CRYPTO_set_locking_callback(openssl_locking_cb_);
diff --git a/src/common/util.c b/src/common/util.c
index 947325108e..d064aceae0 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -3392,8 +3392,8 @@ format_win_cmdline_argument(const char *arg)
smartlist_add(arg_chars, (void*)&backslash);
/* Allocate space for argument, quotes (if needed), and terminator */
- formatted_arg = tor_malloc(sizeof(char) *
- (smartlist_len(arg_chars) + (need_quotes?2:0) + 1));
+ formatted_arg = tor_calloc(sizeof(char),
+ (smartlist_len(arg_chars) + (need_quotes ? 2 : 0) + 1));
/* Add leading quote */
i=0;
@@ -5022,7 +5022,7 @@ tor_check_port_forwarding(const char *filename,
for each smartlist element (one for "-p" and one for the
ports), and one for the final NULL. */
args_n = 1 + 2*smartlist_len(ports_to_forward) + 1;
- argv = tor_malloc_zero(sizeof(char*)*args_n);
+ argv = tor_calloc(sizeof(char *), args_n);
argv[argv_index++] = filename;
SMARTLIST_FOREACH_BEGIN(ports_to_forward, const char *, port) {