Fix null pointers passed to memcmp/memcpy in skip_list #65
+8
-3
@@ -38,6 +38,9 @@ std::span<const uint8_t> keyAfter(Arena &arena, std::span<const uint8_t> key) {
|
||||
|
||||
std::span<const uint8_t> copyToArena(Arena &arena,
|
||||
std::span<const uint8_t> key) {
|
||||
if (key.size() == 0) {
|
||||
return std::span<const uint8_t>();
|
||||
}
|
||||
auto result = std::span<uint8_t>(new (arena) uint8_t[key.size()], key.size());
|
||||
memcpy(result.data(), key.data(), key.size());
|
||||
return result;
|
||||
@@ -97,7 +100,7 @@ force_inline bool getCharacter(const KeyInfo &ki, int character,
|
||||
|
||||
bool operator<(const KeyInfo &lhs, const KeyInfo &rhs) {
|
||||
int i = std::min(lhs.key.size(), rhs.key.size());
|
||||
int c = memcmp(lhs.key.data(), rhs.key.data(), i);
|
||||
int c = i > 0 ? memcmp(lhs.key.data(), rhs.key.data(), i) : 0;
|
||||
|
andrew marked this conversation as resolved
Outdated
|
||||
if (c != 0)
|
||||
return c < 0;
|
||||
|
||||
@@ -287,7 +290,8 @@ private:
|
||||
|
||||
static force_inline bool less(const uint8_t *a, int aLen, const uint8_t *b,
|
||||
int bLen) {
|
||||
int c = memcmp(a, b, std::min(aLen, bLen));
|
||||
int n = std::min(aLen, bLen);
|
||||
int c = n > 0 ? memcmp(a, b, n) : 0;
|
||||
if (c < 0)
|
||||
return true;
|
||||
if (c > 0)
|
||||
@@ -754,7 +758,8 @@ struct __attribute__((visibility("hidden"))) ConflictSet::Impl {
|
||||
|
||||
void addWrites(const ConflictSet::WriteRange *writes, int count,
|
||||
int64_t writeVersion) {
|
||||
auto points = std::vector<KeyInfo>(count * 2);
|
||||
auto points = std::vector<KeyInfo>();
|
||||
points.reserve(count * 2);
|
||||
Arena arena;
|
||||
|
||||
for (int r = 0; r < count; r++) {
|
||||
|
||||
Reference in New Issue
Block a user
If one of them is non-empty, this could compare them incorrectly