[gnome-software/gnome-40: 5/7] gs-details-page: Explicitly handle empty version history array




commit a9597a3a9c04e5dd4571c24dba54abd95eb9fa92
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Apr 29 15:50:36 2021 +0100

    gs-details-page: Explicitly handle empty version history array
    
    This makes the code a bit more robust.
    
    It’s not actually needed, as the current behaviour of
    gs_app_get_version_history() is to either return `NULL` or a non-empty
    array — never an empty array. However, guaranteeing that behaviour would
    defy precedent in other APIs, and be confusing to document, so just
    handle the case of empty arrays in the callers anyway, to make their
    expected behaviour clear.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 src/gs-app-version-history-dialog.c | 2 +-
 src/gs-details-page.c               | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/src/gs-app-version-history-dialog.c b/src/gs-app-version-history-dialog.c
index 94d55cc0c..5262596a2 100644
--- a/src/gs-app-version-history-dialog.c
+++ b/src/gs-app-version-history-dialog.c
@@ -34,7 +34,7 @@ populate_version_history (GsAppVersionHistoryDialog *dialog,
        gs_container_remove_all (GTK_CONTAINER (dialog->listbox));
 
        version_history = gs_app_get_version_history (app);
-       if (version_history == NULL) {
+       if (version_history == NULL || version_history->len == 0) {
                GtkWidget *row;
                row = gs_app_version_history_row_new ();
                gs_app_version_history_row_set_info (GS_APP_VERSION_HISTORY_ROW (row),
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index cf9b4b393..22b38e929 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -1305,7 +1305,7 @@ gs_details_page_refresh_all (GsDetailsPage *self)
 
        /* set version history */
        version_history = gs_app_get_version_history (self->app);
-       if (version_history == NULL) {
+       if (version_history == NULL || version_history->len == 0) {
                const char *version = gs_app_get_version (self->app);
                if (version == NULL || *version == '\0')
                        gtk_widget_set_visible (self->box_version_history_frame, FALSE);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]