Check if statuses is empty

FossilOrigin-Name: b45be4aa14287d1a81f17b3e503383dd3d1427478bf8b0a1e9c6e7b25f8ae957
This commit is contained in:
me@ow.nekobit.net 2022-04-13 01:12:09 +00:00
parent c40977c3f0
commit ec5b72bdde
3 changed files with 7 additions and 6 deletions

1
1
View file

@ -1 +0,0 @@
make: *** No rule to make target '2'. Stop.

View file

@ -123,7 +123,7 @@ int mastodont_request(mastodont_t* data, struct mastodont_request_args* args)
storage->needs_cleanup = 1;
/* Optional */
if (args->callback) args->callback(&results, storage, args->args);
if (args->callback) res = args->callback(&results, storage, args->args);
cleanup_res:
mastodont_fetch_results_cleanup(&results);

View file

@ -118,14 +118,16 @@ int mstdnt_statuses_from_result(struct mstdnt_storage* storage,
{
size_t i = 0;
cJSON* root, *status_j_list;
if (_mstdnt_json_init(&root, results, storage))
return 1;
if (!cJSON_IsArray(root))
if (_mstdnt_json_init(&root, results, storage) &&
!cJSON_IsArray(root))
return 1;
if (size) *size = cJSON_GetArraySize(root);
/* Statuses can be an empty array! */
if (!(size ? *size : cJSON_GetArraySize(root)))
return 0; /* Not an error, but we are done parsing */
/* malloc array - cJSON does a loop to count, let's do it once preferably */
*statuses = calloc(1, (size ? *size : cJSON_GetArraySize(root))
* sizeof(struct mstdnt_status));