From bc9518512266b994ad2af2228bc5672df8ea546b Mon Sep 17 00:00:00 2001 From: "Paul J. Davis" Date: Fri, 15 Sep 2023 09:35:41 -0500 Subject: [PATCH] Fix UBSAN error in the Enumeration CPP API Apparently one of our many build chains decided that faking a default parameter for a `tiledb_datatype_t` is undefined behavior, which, fair enough. The fix should be to just use a std::optional instead. --- tiledb/sm/cpp_api/enumeration_experimental.h | 22 +++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tiledb/sm/cpp_api/enumeration_experimental.h b/tiledb/sm/cpp_api/enumeration_experimental.h index af4b8aa1bf80..fc512618cf9d 100644 --- a/tiledb/sm/cpp_api/enumeration_experimental.h +++ b/tiledb/sm/cpp_api/enumeration_experimental.h @@ -239,17 +239,20 @@ class Enumeration { const std::string& name, std::vector& values, bool ordered = false, - tiledb_datatype_t type = static_cast(255)) { + std::optional type = std::nullopt) { using DataT = impl::TypeHandler; - if (type == static_cast(255)) { - type = DataT::tiledb_type; + tiledb_datatype_t dtype; + if (type.has_value()) { + dtype = type.value(); + } else { + dtype = DataT::tiledb_type; } return create( ctx, name, - type, + dtype, DataT::tiledb_num, ordered, values.data(), @@ -275,13 +278,16 @@ class Enumeration { const std::string& name, std::vector>& values, bool ordered = false, - tiledb_datatype_t type = static_cast(255)) { + std::optional type = std::nullopt) { using DataT = impl::TypeHandler; static_assert( DataT::tiledb_num == 1, "Enumeration string values cannot be compound"); - if (type == static_cast(255)) { - type = DataT::tiledb_type; + tiledb_datatype_t dtype; + if (type.has_value()) { + dtype = type.value(); + } else { + dtype = DataT::tiledb_type; } uint64_t total_size = 0; @@ -303,7 +309,7 @@ class Enumeration { return create( ctx, name, - type, + dtype, TILEDB_VAR_NUM, ordered, data.data(),