mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-23 07:51:10 +01:00
[algs] Add a signed integer clamp helper
Provide an always-inline int64_t overload of hb_clamp_to for cold position formulas that need wider intermediate arithmetic while preserving integer division and rounding semantics. Add boundary tests. This supports the complete position-overflow fix for issue #6151. Testing: meson test -C build --print-errorlogs Assisted-by: Codex <codex@openai.com>
This commit is contained in:
1 parent
3c5af5f416
commit
8ff823adce
2 files changed
+14
No files matched your search
@@ -958,6 +958,17 @@ hb_clamp_to (double v)
|
||||
(double) hb_int_max (T));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static HB_ALWAYS_INLINE T
|
||||
hb_clamp_to (int64_t v)
|
||||
{
|
||||
static_assert (std::is_integral<T>::value && std::is_signed<T>::value, "");
|
||||
|
||||
return (T) hb_clamp (v,
|
||||
(int64_t) hb_int_min (T),
|
||||
(int64_t) hb_int_max (T));
|
||||
}
|
||||
|
||||
/*
|
||||
* Bithacks.
|
||||
*/
|
||||
|
||||
@@ -102,6 +102,9 @@ main (int argc, char **argv)
|
||||
hb_always_assert (hb_clamp_to<int> (1.) == 1);
|
||||
hb_always_assert (hb_clamp_to<int> ((double) INT_MAX + 1.) == INT_MAX);
|
||||
hb_always_assert (hb_clamp_to<int> ((double) INT_MIN - 1.) == INT_MIN);
|
||||
hb_always_assert (hb_clamp_to<int> ((int64_t) 1) == 1);
|
||||
hb_always_assert (hb_clamp_to<int> ((int64_t) INT_MAX + 1) == INT_MAX);
|
||||
hb_always_assert (hb_clamp_to<int> ((int64_t) INT_MIN - 1) == INT_MIN);
|
||||
|
||||
x = 1;
|
||||
hb_always_assert (++hb_inc (x) == 3);
|
||||
|
||||
Reference in new issue
Block a user