Prevent undefined behavior when serializing empty vector (#122)

Since m_get_const_function calls `std::vector<T>::operator[]`, accessing the zeroth element causes undefined behavior. Instead, return a null pointer to make the function behave sanely when vector is empty.
Fix #120
This commit is contained in:
Dan Rose 2020-03-20 14:31:03 -05:00 committed by GitHub
parent 025762ac4f
commit 3ea93f27aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -245,6 +245,8 @@ public:
}
const void * sequence_contents(const void * ptr_to_sequence) const override
{
if(sequence_size(ptr_to_sequence) == 0)
return nullptr;
return m_get_const_function(ptr_to_sequence, 0);
}
};