[algs] Add a float overload of hb_clamp_to (#6195)

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 <noreply@anthropic.com>
This commit is contained in:
Behdad EsfahbodandClaude Fable 5 authored and GitHub committed 2026-08-21 15:07:28 -06:00
1 parent 40949cc70b
commit bc9e8db59b
2 files changed
+11 -2

No files matched your search

+2 -2
View File
@@ -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<hb_position_t> (x_bearing);
extents->width = hb_clamp_to<hb_position_t> ((double) roundf (max_x) - x_bearing);
extents->y_bearing = hb_clamp_to<hb_position_t> (y_bearing);
+9
View File
@@ -958,6 +958,15 @@ hb_clamp_to (double v)
(double) hb_int_max (T));
}
template <typename T>
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<T> ((double) v);
}
template <typename T>
static HB_ALWAYS_INLINE T
hb_clamp_to (int64_t v)