From bc9e8db59b54e2510aa74afc61bfe149ce63a287 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 21 Aug 2026 15:07:28 -0600 Subject: [PATCH] [algs] Add a float overload of hb_clamp_to (#6195) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call sites feeding roundf/floorf/ceilf results into hb_clamp_to promoted float to double implicitly, tripping -Wdouble-promotion under clang. The overload widens explicitly — float cannot represent all integer bounds exactly, so the clamp itself stays in double — and the two glyf extents assignments that promote outside hb_clamp_to get explicit casts. No behavior change. Co-authored-by: Claude Fable 5 --- src/OT/glyf/glyf.hh | 4 ++-- src/hb-algs.hh | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/OT/glyf/glyf.hh b/src/OT/glyf/glyf.hh index 75155b0ca..ce563977a 100644 --- a/src/OT/glyf/glyf.hh +++ b/src/OT/glyf/glyf.hh @@ -357,8 +357,8 @@ struct glyf_accelerator_t return; } { - double x_bearing = roundf (min_x); - double y_bearing = roundf (max_y); + double x_bearing = (double) roundf (min_x); + double y_bearing = (double) roundf (max_y); extents->x_bearing = hb_clamp_to (x_bearing); extents->width = hb_clamp_to ((double) roundf (max_x) - x_bearing); extents->y_bearing = hb_clamp_to (y_bearing); diff --git a/src/hb-algs.hh b/src/hb-algs.hh index 319b65cc1..31361d8b3 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -958,6 +958,15 @@ hb_clamp_to (double v) (double) hb_int_max (T)); } +template +static HB_ALWAYS_INLINE T +hb_clamp_to (float v) +{ + /* Widen explicitly: float cannot represent all integer bounds exactly, + * so the clamp itself is done in double. */ + return hb_clamp_to ((double) v); +} + template static HB_ALWAYS_INLINE T hb_clamp_to (int64_t v)