summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Rosen Penev2020-12-21 23:24:11 +0100
committerGravatar Nikias Bassen2021-01-25 16:20:57 +0100
commitaf9b59e6a1a36997d7017f4841f4a934ca1ade98 (patch)
treef5eb124cbbfbd49b0f6195257752b62176a520ed
parent7b1ccb403ad284b896a4e710fab578e397f101c0 (diff)
downloadlibplist-af9b59e6a1a36997d7017f4841f4a934ca1ade98.tar.gz
libplist-af9b59e6a1a36997d7017f4841f4a934ca1ade98.tar.bz2
Replace malloc + memset with calloc where appropriate
calloc is faster for big allocations. It's also simpler. Signed-off-by: Rosen Penev <rosenp@gmail.com>
-rw-r--r--libcnary/node.c5
-rw-r--r--libcnary/node_list.c5
-rw-r--r--src/xplist.c3
-rw-r--r--tools/plistutil.c3
4 files changed, 6 insertions, 10 deletions
diff --git a/libcnary/node.c b/libcnary/node.c
index c24ca7a..6d68f6e 100644
--- a/libcnary/node.c
+++ b/libcnary/node.c
@@ -46,11 +46,10 @@ void node_destroy(node_t* node) {
node_t* node_create(node_t* parent, void* data) {
int error = 0;
- node_t* node = (node_t*) malloc(sizeof(node_t));
- if(node == NULL) {
+ node_t* node = (node_t*)calloc(1, sizeof(node_t));
+ if (node == NULL) {
return NULL;
}
- memset(node, '\0', sizeof(node_t));
node->data = data;
node->next = NULL;
diff --git a/libcnary/node_list.c b/libcnary/node_list.c
index d071881..aee3bd6 100644
--- a/libcnary/node_list.c
+++ b/libcnary/node_list.c
@@ -33,11 +33,10 @@ void node_list_destroy(node_list_t* list) {
}
node_list_t* node_list_create() {
- node_list_t* list = (node_list_t*) malloc(sizeof(node_list_t));
- if(list == NULL) {
+ node_list_t* list = (node_list_t*)calloc(1, sizeof(node_list_t));
+ if (list == NULL) {
return NULL;
}
- memset(list, '\0', sizeof(node_list_t));
// Initialize structure
list->begin = NULL;
diff --git a/src/xplist.c b/src/xplist.c
index 3a92142..2f98983 100644
--- a/src/xplist.c
+++ b/src/xplist.c
@@ -211,8 +211,7 @@ static void node_to_xml(node_t* node, bytearray_t **outbuf, uint32_t depth)
struct TM _btime;
struct TM *btime = gmtime64_r(&timev, &_btime);
if (btime) {
- val = (char*)malloc(24);
- memset(val, 0, 24);
+ val = (char*)calloc(1, 24);
struct tm _tmcopy;
copy_TM64_to_tm(btime, &_tmcopy);
val_len = strftime(val, 24, "%Y-%m-%dT%H:%M:%SZ", &_tmcopy);
diff --git a/tools/plistutil.c b/tools/plistutil.c
index 989db35..fd0847b 100644
--- a/tools/plistutil.c
+++ b/tools/plistutil.c
@@ -69,8 +69,7 @@ static options_t *parse_arguments(int argc, char *argv[])
{
int i = 0;
- options_t *options = (options_t *) malloc(sizeof(options_t));
- memset(options, 0, sizeof(options_t));
+ options_t *options = (options_t*)calloc(1, sizeof(options_t));
options->out_fmt = 0;
for (i = 1; i < argc; i++)