From: Richard W.M. Jones Date: Thu, 7 Apr 2011 10:24:46 +0000 (+0100) Subject: Clamp progress bar to range 0..1. X-Git-Tag: 0.1.6~2 X-Git-Url: http://git.annexia.org/?p=guestfs-browser.git;a=commitdiff_plain;h=de4375caa0eeb27e8f8e341747e2f99359df745b Clamp progress bar to range 0..1. For unknown reason, this fraction was sometimes out of range. Added a warning message to print position and total if this happens. --- diff --git a/window.ml b/window.ml index 47b9f80..6e720b7 100644 --- a/window.ml +++ b/window.ml @@ -118,9 +118,14 @@ let throbber_idle ws () = let progress ws (position, total) = if position = 0L && total = 1L then ws.progress_bar#pulse () - else - ws.progress_bar#set_fraction - (Int64.to_float position /. Int64.to_float total) + else ( + let frac = Int64.to_float position /. Int64.to_float total in + if frac < 0. || frac > 1. then + eprintf "warning: progress bar out of range: %Ld / %Ld (%g)\n" + position total frac; + let frac = if frac < 0. then 0. else if frac > 1. then 1. else frac in + ws.progress_bar#set_fraction frac + ) (* This is called in the main thread whenever a command fails in the * slave thread. The command queue has been cleared before this is