Skip to content

Commit

Permalink
Fix UBSAN error in the Enumeration CPP API (#4357)
Browse files Browse the repository at this point in the history
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.

---
TYPE: BUG
DESC: Fix UBSAN error in the Enumeration CPP API

(cherry picked from commit 02e6408)
  • Loading branch information
davisp authored and github-actions[bot] committed Sep 18, 2023
1 parent e442a3b commit b799cd3
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions tiledb/sm/cpp_api/enumeration_experimental.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,14 @@ class Enumeration {
const std::string& name,
std::vector<T>& values,
bool ordered = false,
tiledb_datatype_t type = static_cast<tiledb_datatype_t>(255)) {
std::optional<tiledb_datatype_t> type = std::nullopt) {
using DataT = impl::TypeHandler<T>;

if (type == static_cast<tiledb_datatype_t>(255)) {
type = DataT::tiledb_type;
}
tiledb_datatype_t dtype = type.value_or(DataT::tiledb_type);

return create(
ctx,
name,
type,
dtype,
DataT::tiledb_num,
ordered,
values.data(),
Expand All @@ -275,14 +272,11 @@ class Enumeration {
const std::string& name,
std::vector<std::basic_string<T>>& values,
bool ordered = false,
tiledb_datatype_t type = static_cast<tiledb_datatype_t>(255)) {
std::optional<tiledb_datatype_t> type = std::nullopt) {
using DataT = impl::TypeHandler<T>;
static_assert(
DataT::tiledb_num == 1, "Enumeration string values cannot be compound");

if (type == static_cast<tiledb_datatype_t>(255)) {
type = DataT::tiledb_type;
}
tiledb_datatype_t dtype = type.value_or(DataT::tiledb_type);

uint64_t total_size = 0;
for (auto v : values) {
Expand All @@ -303,7 +297,7 @@ class Enumeration {
return create(
ctx,
name,
type,
dtype,
TILEDB_VAR_NUM,
ordered,
data.data(),
Expand Down

0 comments on commit b799cd3

Please sign in to comment.