Skip to content

Commit

Permalink
short circuit serializer::read on empty buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
grisumbras committed Oct 30, 2024
1 parent 7b16bf7 commit 9b3b993
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/boost/json/impl/serializer.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,9 @@ read(char* dest, std::size_t size)
if( !fn0_ )
reset(nullptr);

if(BOOST_JSON_UNLIKELY(size == 0))
return {dest, 0};

detail::stream ss(dest, size);
if(st_.empty())
fn0_(*this, ss);
Expand Down
4 changes: 4 additions & 0 deletions test/serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,10 @@ class serializer_test
void
run()
{
{
serializer sr;
BOOST_ASSERT( sr.read(nullptr, 0).empty() );
}
testNull();
testBoolean();
testString();
Expand Down

0 comments on commit 9b3b993

Please sign in to comment.