提交 9a344e68 编写于 作者: A Alexey Milovidov

Fix UBSan report in FixedHashTable

上级 626b9a3a
......@@ -274,9 +274,21 @@ public:
return iterator(this, ptr);
}
const_iterator end() const { return const_iterator(this, buf + NUM_CELLS); }
const_iterator cend() const { return end(); }
iterator end() { return iterator(this, buf + NUM_CELLS); }
const_iterator end() const
{
/// Avoid UBSan warning about adding zero to nullptr. It is valid in C++20 (and earlier) but not valid in C.
return const_iterator(this, buf ? buf + NUM_CELLS : buf);
}
const_iterator cend() const
{
return end();
}
iterator end()
{
return iterator(this, buf ? buf + NUM_CELLS : buf);
}
public:
......@@ -325,12 +337,17 @@ public:
Cell::State::write(wb);
DB::writeVarUInt(m_size, wb);
if (!buf)
return;
for (auto ptr = buf, buf_end = buf + NUM_CELLS; ptr < buf_end; ++ptr)
{
if (!ptr->isZero(*this))
{
DB::writeVarUInt(ptr - buf);
ptr->write(wb);
}
}
}
void writeText(DB::WriteBuffer & wb) const
......@@ -338,6 +355,9 @@ public:
Cell::State::writeText(wb);
DB::writeText(m_size, wb);
if (!buf)
return;
for (auto ptr = buf, buf_end = buf + NUM_CELLS; ptr < buf_end; ++ptr)
{
if (!ptr->isZero(*this))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册