From 23c99ba5a23f23ac3df531b4507816c0a89a6f2c Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Wed, 23 Mar 2022 19:09:40 +0000 Subject: [PATCH] Use calloc for certain things Some information needs to be zero'd out, calloc helps here FossilOrigin-Name: d8b7f456384ed1c29b0f4fddafa1bae768990d0fce455aca3f84123561640a89 --- src/account.c | 2 +- src/attachment.c | 2 +- src/emoji.c | 2 +- src/notification.c | 2 +- src/status.c | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/account.c b/src/account.c index b79c0f0..edcaef0 100644 --- a/src/account.c +++ b/src/account.c @@ -35,7 +35,7 @@ void _mstdnt_val_malloc_account_call(cJSON* v, void* _type) { struct mstdnt_account** type = _type; - *type = malloc(sizeof(struct mstdnt_account)); + *type = calloc(1, sizeof(struct mstdnt_account)); if (*type) mstdnt_account_from_json(*type, v->child); diff --git a/src/attachment.c b/src/attachment.c index d5b8cd4..e8c26eb 100644 --- a/src/attachment.c +++ b/src/attachment.c @@ -53,7 +53,7 @@ void _mstdnt_val_attachments_call(cJSON* v, void* _type) return; } - *attachments = malloc(sizeof(struct mstdnt_attachment) * size); + *attachments = calloc(1, sizeof(struct mstdnt_attachment) * size); if (*attachments == NULL) return; diff --git a/src/emoji.c b/src/emoji.c index 0a1b049..a9de512 100644 --- a/src/emoji.c +++ b/src/emoji.c @@ -48,7 +48,7 @@ void _mstdnt_val_emoji_reactions_call(cJSON* v, void* _type) return; } - *emos = malloc(sizeof(struct mstdnt_emoji_reaction) * size); + *emos = calloc(1, sizeof(struct mstdnt_emoji_reaction) * size); if (*emos == NULL) return; diff --git a/src/notification.c b/src/notification.c index f0afce5..a20fb33 100644 --- a/src/notification.c +++ b/src/notification.c @@ -76,7 +76,7 @@ int mstdnt_notifications_from_result(struct mstdnt_fetch_results* results, if (size) *size = cJSON_GetArraySize(root); /* malloc array - cJSON does a loop to count, let's do it once preferably */ - *notif = malloc((size ? *size : cJSON_GetArraySize(root)) + *notif = calloc(1, (size ? *size : cJSON_GetArraySize(root)) * sizeof(struct mstdnt_notification)); if (*notif == NULL) return 1; diff --git a/src/status.c b/src/status.c index 6dd6005..e638a62 100644 --- a/src/status.c +++ b/src/status.c @@ -34,7 +34,7 @@ void _mstdnt_val_malloc_status_call(cJSON* v, void* _type) { struct mstdnt_status** type = _type; - *type = malloc(sizeof(struct mstdnt_status)); + *type = calloc(1, sizeof(struct mstdnt_status)); if (*type) mstdnt_status_from_json(*type, v->child); @@ -118,7 +118,7 @@ int mstdnt_statuses_from_result(struct mstdnt_storage* storage, if (size) *size = cJSON_GetArraySize(root); /* malloc array - cJSON does a loop to count, let's do it once preferably */ - *statuses = malloc((size ? *size : cJSON_GetArraySize(root)) + *statuses = calloc(1, (size ? *size : cJSON_GetArraySize(root)) * sizeof(struct mstdnt_status)); if (*statuses == NULL) return 1;