From 320f9f084ec77b8543e17268ec5e2b3655f50082 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 28 Jun 2026 16:56:33 +0300 Subject: Fix stats gauge bars rendering at width:0% (stats_category_max) Regression from or0 (STATS_* accessors): stats_category_max compared values via `(( _stats_counts_ref[key] > max ))`. For a nameref to an ASSOCIATIVE array, an arithmetic subscript is itself arithmetic-evaluated, so a string key (e.g. "sony") resolves to an unset variable -> 0, i.e. it always read index 0 and returned max 0. Every bar then scaled to width:0% (counts/percentages were unaffected, so only the bars looked broken). Read the value through a quoted ${assoc[$key]} expansion first, then compare. The byte-identical double-render test missed this because both renders were equally broken; added explicit non-zero bar-width assertions (100% / 50%) to test_render_stats_page_renders_sections_and_escapes. Co-Authored-By: Claude Opus 4.8 --- src/lib/stats-aggregate.source.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/lib/stats-aggregate.source.sh') diff --git a/src/lib/stats-aggregate.source.sh b/src/lib/stats-aggregate.source.sh index 3c013b3..ff06d15 100644 --- a/src/lib/stats-aggregate.source.sh +++ b/src/lib/stats-aggregate.source.sh @@ -772,11 +772,19 @@ stats_category_size() { stats_category_max() { local -n _stats_counts_ref="$1"; shift local key + local -i value local -i max=0 for key in "${!_stats_counts_ref[@]}"; do - if (( _stats_counts_ref[key] > max )); then - max=${_stats_counts_ref[$key]} + # Read the value through a quoted ${assoc[$key]} expansion FIRST, then + # compare. Do NOT write "(( _stats_counts_ref[key] > max ))": inside an + # arithmetic context an associative subscript is itself arithmetic- + # evaluated, so a string key (e.g. "sony") resolves to an unset var -> 0, + # i.e. it would always read index 0 and report max 0 (broken zero-width + # bars). The string-keyed expansion below is the only correct read. + value=${_stats_counts_ref[$key]} + if (( value > max )); then + max=$value fi done printf '%d' "$max" -- cgit v1.2.3