From 78766ee1e1ca694f610c7a3a68f16a9509a9e4d0 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Mon, 11 Apr 2022 21:04:48 +0000 Subject: [PATCH] Handle list errors FossilOrigin-Name: d3aa61e2ff4bbc189e0f7953a7fbdf3a8ba19d95800487ae7eede6082606aacb --- src/lists.c | 8 +++----- src/timeline.c | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/lists.c b/src/lists.c index 235c5f8..a514947 100644 --- a/src/lists.c +++ b/src/lists.c @@ -63,11 +63,10 @@ char* construct_lists_view(char* lists_string, int* size) void content_lists(struct session* ssn, mastodont_t* api, char** data) { - int cleanup = 0; struct mstdnt_list* lists; size_t size_list; struct mstdnt_storage storage = { 0 }; - char* lists_format; + char* lists_format = NULL; char* lists_page = NULL; if (mastodont_get_lists(api, &lists, &storage, &size_list)) @@ -77,8 +76,7 @@ void content_lists(struct session* ssn, mastodont_t* api, char** data) else { lists_format = construct_lists(lists, size_list, NULL); if (!lists_format) - lists_format = "Error in malloc!"; - cleanup = 1; + lists_format = construct_error("No lists", E_ERROR, 1, NULL); lists_page = construct_lists_view(lists_format, NULL); } @@ -94,6 +92,6 @@ void content_lists(struct session* ssn, mastodont_t* api, char** data) // Cleanup mastodont_storage_cleanup(&storage); - if (cleanup) free(lists_format); + if (lists_format) free(lists_format); if (lists_page) free(lists_page); } diff --git a/src/timeline.c b/src/timeline.c index 99d7711..0342e6c 100644 --- a/src/timeline.c +++ b/src/timeline.c @@ -102,7 +102,6 @@ void tl_public(struct session* ssn, mastodont_t* api, int local) void tl_list(struct session* ssn, mastodont_t* api, char* list_id) { - int cleanup = 0; size_t status_count, statuses_html_count; struct mstdnt_status* statuses; struct mstdnt_storage storage = { 0 }; @@ -120,14 +119,13 @@ void tl_list(struct session* ssn, mastodont_t* api, char* list_id) if (mastodont_timeline_list(api, list_id, &args, &storage, &statuses, &status_count)) { - status_format = "An error occured loading the timeline"; + status_format = construct_error(storage.error, E_ERROR, 1, NULL); } else { // Construct statuses into HTML status_format = construct_statuses(api, statuses, status_count, &statuses_html_count); if (!status_format) - status_format = "Error in malloc!"; - cleanup = 1; + status_format = construct_error("No statuses", E_ERROR, 1, NULL); } // Create post box @@ -149,7 +147,7 @@ void tl_list(struct session* ssn, mastodont_t* api, char* list_id) // Cleanup mastodont_storage_cleanup(&storage); mstdnt_cleanup_statuses(statuses, status_count); - if (cleanup) free(status_format); + free(status_format); if (post_box) free(post_box); if (output) free(output); }