From 2da36fd72ab75cb41409bb70cb0d18eecf7b6e5f Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 16 Aug 2025 18:11:09 +0900 Subject: [PATCH 1/2] DiskBar: Add some safety checks to constraints calculations --- src/Widgets/DiskBar.vala | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Widgets/DiskBar.vala b/src/Widgets/DiskBar.vala index cd29ca842..5a9115f96 100644 --- a/src/Widgets/DiskBar.vala +++ b/src/Widgets/DiskBar.vala @@ -116,6 +116,9 @@ public class Installer.DiskBar: Gtk.Box { ); } + // make sure if somehow used_sectors > total_disk_sectors, we clamp it to total_disk_sectors + used_sectors = uint64.min (used_sectors, total_disk_sectors); + // If more than 1% of the disk is unused, show a block for the unused space var unused_sectors = total_disk_sectors - used_sectors; if ((double) unused_sectors / total_disk_sectors > 0.01) { @@ -147,8 +150,11 @@ public class Installer.DiskBar: Gtk.Box { } private void append_partition (Gtk.Widget widget, double percentage) { - // Truncate to 2 decimal places (round down), to ensure we don't go over 100% because of rounding errors - percentage = (int)(percentage * 100) / 100.0; + // Truncate to 2 decimal places (round down), to ensure we don't go over 100% because of rounding errors. + // Also make sure percentage is never 0, otherwise we can assertion error: + // gtk_constraint_expression_new_subject: assertion failed: (!G_APPROX_VALUE (term->coefficient, 0.0, 0.001)) + // Also we assume partitions.size is less than 100 + percentage = ((int) (percentage * 100) / 100.0).clamp (0.001, 1.0 - partitions.size / 100.0); widget.set_parent (this); From 916df12196d963448b6620e5c513b93c67b17c74 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 16 Aug 2025 18:16:27 +0900 Subject: [PATCH 2/2] 1% as minimum partition size --- src/Widgets/DiskBar.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Widgets/DiskBar.vala b/src/Widgets/DiskBar.vala index 5a9115f96..4d82986f7 100644 --- a/src/Widgets/DiskBar.vala +++ b/src/Widgets/DiskBar.vala @@ -154,7 +154,7 @@ public class Installer.DiskBar: Gtk.Box { // Also make sure percentage is never 0, otherwise we can assertion error: // gtk_constraint_expression_new_subject: assertion failed: (!G_APPROX_VALUE (term->coefficient, 0.0, 0.001)) // Also we assume partitions.size is less than 100 - percentage = ((int) (percentage * 100) / 100.0).clamp (0.001, 1.0 - partitions.size / 100.0); + percentage = ((int) (percentage * 100) / 100.0).clamp (0.01, 1.0 - partitions.size / 100.0); widget.set_parent (this);