[gnome-builder/wip/gtk4-port: 1583/1774] libide/core: handle fractions out of bounds




commit 6513450e6094fcf93473f3718f8d231e60f219cc
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jun 21 17:02:04 2022 -0700

    libide/core: handle fractions out of bounds

 src/libide/core/ide-notification.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/src/libide/core/ide-notification.c b/src/libide/core/ide-notification.c
index ab1fa943b..bb3a5bfeb 100644
--- a/src/libide/core/ide-notification.c
+++ b/src/libide/core/ide-notification.c
@@ -1116,12 +1116,19 @@ ide_notification_file_progress_callback (goffset  current_num_bytes,
                                          gpointer user_data)
 {
   IdeNotification *self = user_data;
-  gdouble fraction = 0.0;
+  double fraction;
 
   g_return_if_fail (IDE_IS_NOTIFICATION (self));
 
   if (total_num_bytes)
-    fraction = (gdouble)current_num_bytes / (gdouble)total_num_bytes;
+    fraction = (double)current_num_bytes / (double)total_num_bytes;
+  else
+    fraction = .0;
+
+  if (fraction < .0)
+    fraction = .0;
+  else if (fraction > 1.)
+    fraction = 1.;
 
   ide_notification_set_progress (self, fraction);
 }


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