diff --git a/include/rocksdb/slice.h b/include/rocksdb/slice.h index fe8dee00f04a7946c45c43ee25de96d0b0fde5f1..d1786dd44da25184a8fd3386f705d18fe09218ff 100644 --- a/include/rocksdb/slice.h +++ b/include/rocksdb/slice.h @@ -213,8 +213,18 @@ inline bool operator!=(const Slice& x, const Slice& y) { return !(x == y); } +// UBSAN complain that we pass nullptr to memcmp that's fine since +// we always do that for a string of len = 0 +#ifdef ROCKSDB_UBSAN_RUN +#if defined(__clang__) +__attribute__((__no_sanitize__("undefined"))) +#elif defined(__GNUC__) +__attribute__((__no_sanitize_undefined__)) +#endif +#endif inline int Slice::compare(const Slice& b) const { const size_t min_len = (size_ < b.size_) ? size_ : b.size_; + assert((data_ != nullptr && b.data_ != nullptr) || min_len == 0); int r = memcmp(data_, b.data_, min_len); if (r == 0) { if (size_ < b.size_) r = -1;