summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2018-08-08 21:36:28 +0300
committerAmar Tumballi <amarts@redhat.com>2018-09-04 05:09:09 +0000
commit5276e8f27e3021d5da3d3055caed6f9a1d964c93 (patch)
tree23f6a1fedc8d5bf4b752eab2ae5a451c57a80fa0 /tests
parent81cbbfd1d870bea49b8aafe7bebb9e8251190918 (diff)
multiple files: calloc -> malloc
xlators/cluster/stripe/src/stripe-helpers.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible xlators/cluster/dht/src/tier.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible xlators/cluster/dht/src/dht-layout.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible xlators/cluster/dht/src/dht-helper.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible xlators/cluster/dht/src/dht-common.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible xlators/cluster/afr/src/afr.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible xlators/cluster/afr/src/afr-inode-read.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible tests/bugs/replicate/bug-1250170-fsync.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible tests/basic/gfapi/gfapi-async-calls-test.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible tests/basic/ec/ec-fast-fgetxattr.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible rpc/xdr/src/glusterfs3.h: Move to GF_MALLOC() instead of GF_CALLOC() when possible rpc/rpc-transport/socket/src/socket.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible rpc/rpc-lib/src/rpc-clnt.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible extras/geo-rep/gsync-sync-gfid.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible cli/src/cli-xml-output.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible cli/src/cli-rpc-ops.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible cli/src/cli-cmd-volume.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible cli/src/cli-cmd-system.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible cli/src/cli-cmd-snapshot.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible cli/src/cli-cmd-peer.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible cli/src/cli-cmd-global.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible It doesn't make sense to calloc (allocate and clear) memory when the code right away fills that memory with data. It may be optimized by the compiler, or have a microscopic performance improvement. In some cases, also changed allocation size to be sizeof some struct or type instead of a pointer - easier to read. In some cases, removed redundant strlen() calls by saving the result into a variable. 1. Only done for the straightforward cases. There's room for improvement. 2. Please review carefully, especially for string allocation, with the terminating NULL string. Only compile-tested! updates: bz#1193929 Original-Author: Yaniv Kaul <ykaul@redhat.com> Signed-off-by: Yaniv Kaul <ykaul@redhat.com> Signed-off-by: Amar Tumballi <amarts@redhat.com> Change-Id: I16274dca4078a1d06ae09a0daf027d734b631ac2
Diffstat (limited to 'tests')
-rw-r--r--tests/basic/ec/ec-fast-fgetxattr.c2
-rw-r--r--tests/basic/gfapi/gfapi-async-calls-test.c2
-rw-r--r--tests/bugs/replicate/bug-1250170-fsync.c4
3 files changed, 4 insertions, 4 deletions
diff --git a/tests/basic/ec/ec-fast-fgetxattr.c b/tests/basic/ec/ec-fast-fgetxattr.c
index ecdbcbe44a6..b40dda65de5 100644
--- a/tests/basic/ec/ec-fast-fgetxattr.c
+++ b/tests/basic/ec/ec-fast-fgetxattr.c
@@ -16,7 +16,7 @@ fill_iov (struct iovec *iov, char fillchar, int count)
{
int ret = -1;
- iov->iov_base = calloc (count + 1, sizeof(fillchar));
+ iov->iov_base = malloc (count + 1);
if (iov->iov_base == NULL) {
return ret;
} else {
diff --git a/tests/basic/gfapi/gfapi-async-calls-test.c b/tests/basic/gfapi/gfapi-async-calls-test.c
index 58046861668..b9f29a44ac0 100644
--- a/tests/basic/gfapi/gfapi-async-calls-test.c
+++ b/tests/basic/gfapi/gfapi-async-calls-test.c
@@ -21,7 +21,7 @@ fill_iov (struct iovec *iov, char fillchar, int count)
{
int ret = -1;
- iov->iov_base = calloc (count + 1, sizeof(fillchar));
+ iov->iov_base = malloc (count + 1);
if (iov->iov_base == NULL) {
return ret;
} else {
diff --git a/tests/bugs/replicate/bug-1250170-fsync.c b/tests/bugs/replicate/bug-1250170-fsync.c
index 1d3025bcd9f..421fb5c5067 100644
--- a/tests/bugs/replicate/bug-1250170-fsync.c
+++ b/tests/bugs/replicate/bug-1250170-fsync.c
@@ -26,9 +26,9 @@ int main (int argc, char **argv)
file = argv[1];
buf_size = 1024;
- buffer = calloc(1, buf_size);
+ buffer = malloc(buf_size);
if (!buffer) {
- perror("calloc");
+ perror("malloc");
return -1;
}
memset (buffer, 'R', buf_size);