From 8cc47f4a9cee447da1e113649ecf55b92f8646e8 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 24 Apr 2024 20:02:11 -0400 Subject: [PATCH] xo-unit: bugfix: out-of-bounds access in almost-unreachable path --- include/xo/unit/basis_unit_abbrev.hpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/include/xo/unit/basis_unit_abbrev.hpp b/include/xo/unit/basis_unit_abbrev.hpp index 31e39565..49216d17 100644 --- a/include/xo/unit/basis_unit_abbrev.hpp +++ b/include/xo/unit/basis_unit_abbrev.hpp @@ -182,6 +182,8 @@ namespace xo { return fallback_unit_abbrev(scalefactor, dim::price); } + // ----- basis_unit2_abbrev ----- + static constexpr basis_unit2_abbrev_type basis_unit2_abbrev(dim native_dim, @@ -200,16 +202,13 @@ namespace xo { return price_unit2_abbrev(scalefactor); case dim::invalid: case dim::n_dim: + return basis_unit2_abbrev_type(); break; } - /* e.g. unit of '1000 grams' will have abbrev '1000g' in absence - * of a specialization for scaled_native_unit_abbrev - */ - return (basis_unit2_abbrev_type::from_flatstring - (flatstring_concat - (scalefactor.to_str(), - native_unit2_v[static_cast(native_dim)].abbrev_str()))); + /* unreachable (for well-constructed dim instances) */ + + return basis_unit2_abbrev_type(); } } /*namespace abbrev*/ } /*namespace qty*/