Skip to content

Commit 539d9c6

Browse files
committed
fix ubsan
1 parent 5c703d9 commit 539d9c6

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/iceberg/update/update_properties.cc

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919

2020
#include "iceberg/update/update_properties.h"
2121

22+
#include <charconv>
2223
#include <cstdint>
2324
#include <memory>
25+
#include <system_error>
2426

2527
#include "iceberg/metrics_config.h"
2628
#include "iceberg/result.h"
@@ -83,21 +85,23 @@ Result<PendingUpdate::ApplyResult> UpdateProperties::Apply() {
8385

8486
auto iter = updates_.find(TableProperties::kFormatVersion.key());
8587
if (iter != updates_.end()) {
86-
try {
87-
int parsed_version = std::stoi(iter->second);
88-
if (parsed_version > TableMetadata::kSupportedTableFormatVersion) {
89-
return InvalidArgument(
90-
"Cannot upgrade table to unsupported format version: v{} (supported: v{})",
91-
parsed_version, TableMetadata::kSupportedTableFormatVersion);
92-
}
93-
format_version_ = static_cast<int8_t>(parsed_version);
94-
} catch (const std::invalid_argument& e) {
95-
return InvalidArgument("Invalid format version '{}': not a valid integer",
96-
iter->second);
97-
} catch (const std::out_of_range& e) {
98-
return InvalidArgument("Format version '{}' is out of range", iter->second);
88+
int parsed_version = 0;
89+
const auto& val = iter->second;
90+
auto [ptr, ec] = std::from_chars(val.data(), val.data() + val.size(), parsed_version);
91+
92+
if (ec == std::errc::invalid_argument) {
93+
return InvalidArgument("Invalid format version '{}': not a valid integer", val);
94+
} else if (ec == std::errc::result_out_of_range) {
95+
return InvalidArgument("Format version '{}' is out of range", val);
9996
}
10097

98+
if (parsed_version > TableMetadata::kSupportedTableFormatVersion) {
99+
return InvalidArgument(
100+
"Cannot upgrade table to unsupported format version: v{} (supported: v{})",
101+
parsed_version, TableMetadata::kSupportedTableFormatVersion);
102+
}
103+
format_version_ = static_cast<int8_t>(parsed_version);
104+
101105
updates_.erase(iter);
102106
}
103107

0 commit comments

Comments
 (0)