From d0968c5ce97e435b014874d6cd2c7449502f8476 Mon Sep 17 00:00:00 2001 From: LagoLunatic Date: Mon, 19 Oct 2026 14:49:11 -0400 Subject: [PATCH 1/2] Avoid rounding 99.995% matches up to 100% in the function diff view --- objdiff-cli/src/views/function_diff.rs | 3 ++- objdiff-core/src/util.rs | 9 +++++++++ objdiff-gui/src/views/diff.rs | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/objdiff-cli/src/views/function_diff.rs b/objdiff-cli/src/views/function_diff.rs index e7cab796..9d330d68 100644 --- a/objdiff-cli/src/views/function_diff.rs +++ b/objdiff-cli/src/views/function_diff.rs @@ -10,6 +10,7 @@ use objdiff_core::{ display::{DiffText, DiffTextColor, HighlightKind, display_row}, }, obj::Object, + util::format_percent, }; use ratatui::{ Frame, @@ -88,7 +89,7 @@ impl UiView for FunctionDiffUi { .and_then(|(_, _, d)| d.match_percent) { line_r.spans.push(Span::styled( - format!("{percent:.2}% "), + format!("{} ", format_percent(percent)), Style::new().fg(match_percent_color(percent)), )); } diff --git a/objdiff-core/src/util.rs b/objdiff-core/src/util.rs index a6783c98..34295e38 100644 --- a/objdiff-core/src/util.rs +++ b/objdiff-core/src/util.rs @@ -26,6 +26,15 @@ impl fmt::UpperHex for ReallySigned { } } +/// Formats a progress percentage as a string, and prevents partial matches from being rounded to 0.00% or 100.00%. +pub fn format_percent(value: f32) -> String { + let mut value = value; + if value > 0.0 && value < 100.0 { + value = value.clamp(0.01, 99.99); + } + format!("{value:.2}%") +} + pub fn read_u32(obj_file: &object::File, reader: &mut &[u8]) -> Result { ensure!(reader.len() >= 4, "Not enough bytes to read u32"); let value = reader[..4].try_into()?; diff --git a/objdiff-gui/src/views/diff.rs b/objdiff-gui/src/views/diff.rs index 173abf29..bb2fdbe9 100644 --- a/objdiff-gui/src/views/diff.rs +++ b/objdiff-gui/src/views/diff.rs @@ -12,7 +12,7 @@ use objdiff_core::{ }, }, obj::{InstructionArgValue, Object, Symbol}, - util::ReallySigned, + util::{ReallySigned, format_percent}, }; use time::format_description; @@ -535,7 +535,7 @@ pub fn diff_view_ui( let mut needs_separator = false; if let Some(match_percent) = symbol_diff.match_percent { let response = ui.label( - RichText::new(format!("{match_percent:.2}%")) + RichText::new(format_percent(match_percent)) .font(appearance.code_font.clone()) .color(match_color_for_symbol(match_percent, appearance)), ); From 7e1998840ebf802a03f470a5bd8175b3df368e32 Mon Sep 17 00:00:00 2001 From: LagoLunatic Date: Mon, 19 Oct 2026 14:53:53 -0400 Subject: [PATCH 2/2] Fix objdiff-wasm build --- objdiff-core/src/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/objdiff-core/src/util.rs b/objdiff-core/src/util.rs index 34295e38..129dd985 100644 --- a/objdiff-core/src/util.rs +++ b/objdiff-core/src/util.rs @@ -1,4 +1,4 @@ -use alloc::{format, vec::Vec}; +use alloc::{format, string::String, vec::Vec}; use core::fmt; use anyhow::{Result, ensure};