Skip to content

Commit 8421526

Browse files
authored
fix: fix ub in Blob (alibaba#319)
1 parent 4d23073 commit 8421526

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

src/paimon/common/data/blob.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class MemoryPool;
3535

3636
class Blob::Impl {
3737
public:
38-
Impl(std::unique_ptr<BlobDescriptor>&& descriptor, const std::string& uri)
39-
: descriptor_(std::move(descriptor)), uri_(uri) {}
38+
explicit Impl(std::unique_ptr<BlobDescriptor>&& descriptor)
39+
: descriptor_(std::move(descriptor)) {}
4040

4141
PAIMON_UNIQUE_PTR<Bytes> SerializeDescriptor(const std::shared_ptr<MemoryPool>& pool) const {
4242
return descriptor_->Serialize(pool);
@@ -47,12 +47,11 @@ class Blob::Impl {
4747
}
4848

4949
const std::string& Uri() const {
50-
return uri_;
50+
return descriptor_->Uri();
5151
}
5252

5353
private:
5454
std::unique_ptr<BlobDescriptor> descriptor_;
55-
std::string uri_;
5655
};
5756

5857
Result<std::unique_ptr<Blob>> Blob::FromPath(const std::string& path) {
@@ -64,7 +63,7 @@ Result<std::unique_ptr<Blob>> Blob::FromPath(const std::string& path, int64_t of
6463
PAIMON_ASSIGN_OR_RAISE(std::string normalized_path, PathUtil::NormalizePath(path));
6564
PAIMON_ASSIGN_OR_RAISE(std::unique_ptr<BlobDescriptor> descriptor,
6665
BlobDescriptor::Create(normalized_path, offset, length));
67-
auto impl = std::make_unique<Blob::Impl>(std::move(descriptor), descriptor->Uri());
66+
auto impl = std::make_unique<Impl>(std::move(descriptor));
6867
return std::unique_ptr<Blob>(new Blob(std::move(impl)));
6968
}
7069

@@ -75,7 +74,7 @@ Result<std::unique_ptr<Blob>> Blob::FromDescriptor(const char* buffer, uint64_t
7574
PAIMON_ASSIGN_OR_RAISE(std::unique_ptr<BlobDescriptor> descriptor,
7675
BlobDescriptor::Deserialize(buffer, length));
7776

78-
auto impl = std::make_unique<Impl>(std::move(descriptor), descriptor->Uri());
77+
auto impl = std::make_unique<Impl>(std::move(descriptor));
7978
return std::unique_ptr<Blob>(new Blob(std::move(impl)));
8079
}
8180

0 commit comments

Comments
 (0)