gtk4-demo: Avoid a critical from a11y code
authorMatthias Clasen <mclasen@redhat.com>
Fri, 28 Oct 2022 15:59:35 +0000 (11:59 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 28 Oct 2022 16:02:23 +0000 (12:02 -0400)
Even though we want to be accessible,
we must not divide by zero.

demos/gtk-demo/listview_words.c

index 9b3e6a636d52196dfb55617e81678bc092444e92..06c6394368972979ba84f77b3559a6ee9c206787 100644 (file)
@@ -42,7 +42,7 @@ update_title_cb (GtkFilterListModel *model)
   title = g_strdup_printf ("%u lines", g_list_model_get_n_items (G_LIST_MODEL (model)));
 
   gtk_widget_set_visible (progress, pending != 0);
-  gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress), (total - pending) / (double) total);
+  gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress), total > 0 ? (total - pending) / (double) total : 0.);
   gtk_window_set_title (GTK_WINDOW (window), title);
   g_free (title);
 }