Make sure values are empty

FossilOrigin-Name: 7ee2fc4f2451db50f988d5675249cec6528f4224ae9356d91b305fd6b750c4b1
This commit is contained in:
me@ow.nekobit.net 2022-03-30 19:06:21 +00:00
parent 2c509d650c
commit 6f5bdf2ee1
10 changed files with 52 additions and 3 deletions

View file

@ -13,6 +13,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdlib.h>
#include <mastodont_account.h>
#include <mastodont_request.h>
@ -100,6 +101,10 @@ int mastodont_get_account(mastodont_t* data,
int mstdnt_account_from_json(struct mstdnt_account* acct, cJSON* js)
{
cJSON* v;
/* Zero out */
memset(acct, 0, sizeof(struct mstdnt_account));
struct _mstdnt_val_ref refs[] = {
{ "id", &(acct->id), _mstdnt_val_string_call },
{ "username", &(acct->username), _mstdnt_val_string_call },

View file

@ -13,6 +13,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdlib.h>
#include <mastodont_json_helper.h>
#include <mastodont_application.h>
@ -24,6 +25,10 @@ int mstdnt_app_result(struct mstdnt_fetch_results* results,
struct mstdnt_app* app)
{
cJSON* root, *v;
/* Zero out */
memset(storage, 0, sizeof(struct mstdnt_app));
if (_mstdnt_json_init(&root, results, storage))
return 1;

View file

@ -13,6 +13,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdlib.h>
#include <mastodont_attachment.h>
#include <mastodont_json_helper.h>
@ -20,6 +21,10 @@
static void load_attachment_from_json(struct mstdnt_attachment* att, cJSON* att_json)
{
cJSON* it;
/* Zero out */
memset(att, 0, sizeof(struct mstdnt_attachment));
struct _mstdnt_val_ref refs[] = {
{ "id", &(att->id), _mstdnt_val_string_call },
/* TODO type */

View file

@ -13,6 +13,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdlib.h>
#include <mastodont_json_helper.h>
#include <mastodont_emoji.h>
@ -20,6 +21,10 @@
static void load_emoji_reacts_from_json(struct mstdnt_emoji_reaction* emo, cJSON* emo_json)
{
cJSON* it;
/* Zero out */
memset(emo, 0, sizeof(struct mstdnt_emoji_reaction));
struct _mstdnt_val_ref refs[] = {
{ "name", &(emo->name), _mstdnt_val_string_call },
{ "count", &(emo->count), _mstdnt_val_uint_call },

View file

@ -24,6 +24,10 @@ int mstdnt_check_error(struct mstdnt_fetch_results* results,
if (_mstdnt_json_init(&root, results, storage))
return 1;
/* Make sure empty */
storage->error = NULL;
storage->error_description = NULL;
struct _mstdnt_val_ref refs[] = {
{ "error", &(storage->error), _mstdnt_val_string_call },
{ "error_description", &(storage->error_description), _mstdnt_val_string_call },

View file

@ -13,6 +13,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdlib.h>
#include <mastodont_list.h>
#include <mastodont_json_helper.h>
@ -27,6 +28,10 @@ struct mstdnt_get_lists_args {
int mstdnt_list_from_json(struct mstdnt_list* list, cJSON* js)
{
cJSON* v;
/* Zero out */
memset(list, 0, sizeof(struct mstdnt_list));
struct _mstdnt_str_val strings[] = {
{ "id", &(list->id) },
{ "title", &(list->title) },

View file

@ -48,6 +48,9 @@ int mstdnt_notification_from_json(struct mstdnt_notification* notif, cJSON* js)
{
cJSON* v;
/* Zero out */
memset(notif, 0, sizeof(struct mstdnt_notification));
struct _mstdnt_val_ref vals[] = {
{ "account", &(notif->account), _mstdnt_val_malloc_account_call },
{ "created_at", &(notif->created_at), _mstdnt_val_string_call },

View file

@ -13,6 +13,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <mastodont_json_helper.h>
#include <mastodont_pleroma.h>
@ -20,6 +21,9 @@ int mstdnt_status_pleroma_from_json(struct mstdnt_status_pleroma* pleroma, cJSON
{
cJSON* v;
/* Zero out */
memset(pleroma, 0, sizeof(struct mstdnt_status_pleroma));
struct _mstdnt_generic_args emo_args = {
&(pleroma->emoji_reactions),
&(pleroma->emoji_reactions_len),

View file

@ -13,6 +13,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <mastodont_request.h>
@ -28,6 +29,8 @@ int mastodont_request(mastodont_t* data, struct mastodont_request_args* args)
_mstdnt_query_string(data, args->url, args->params_query, args->params_query_len) :
args->url;
/* Zero out */
memset(storage, 0, sizeof(struct mstdnt_storage));
storage->needs_cleanup = 0;
if (args->params_post)

View file

@ -43,7 +43,10 @@ void _mstdnt_val_malloc_status_call(cJSON* v, void* _type)
int mstdnt_status_from_json(struct mstdnt_status* status, cJSON* js)
{
cJSON* v;
/* Zero out */
memset(status, 0, sizeof(struct mstdnt_status));
struct _mstdnt_generic_args att_args = {
&(status->media_attachments),
&(status->media_attachments_len),
@ -297,6 +300,13 @@ int mstdnt_status_context_from_result(struct mstdnt_fetch_results* results,
size_t* size_after)
{
cJSON* root;
/* Empty data */
*size_before = 0;
*size_after = 0;
*statuses_before = NULL;
*statuses_after = NULL;
if (_mstdnt_json_init(&root, results, storage))
return 1;
@ -321,7 +331,7 @@ int mstdnt_status_context_from_json(struct mstdnt_fetch_results* results,
cJSON* v, *status_item;
size_t* size_ptr = NULL;
struct mstdnt_status** stat_ptr = NULL;
/* Empty data */
*size_before = 0;
*size_after = 0;
@ -347,7 +357,7 @@ int mstdnt_status_context_from_json(struct mstdnt_fetch_results* results,
if (cJSON_GetArraySize(v) <= 0)
continue;
*stat_ptr = malloc(cJSON_GetArraySize(v) * sizeof(struct mstdnt_status));
*stat_ptr = calloc(1, cJSON_GetArraySize(v) * sizeof(struct mstdnt_status));
if (*stat_ptr == NULL)
return 1;