diff --git a/include/boost/json/impl/serializer.ipp b/include/boost/json/impl/serializer.ipp index 5a0baea32..89c6b4ade 100644 --- a/include/boost/json/impl/serializer.ipp +++ b/include/boost/json/impl/serializer.ipp @@ -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); diff --git a/test/serializer.cpp b/test/serializer.cpp index 5cb257b6e..d2f82a9e1 100644 --- a/test/serializer.cpp +++ b/test/serializer.cpp @@ -896,6 +896,10 @@ class serializer_test void run() { + { + serializer sr; + BOOST_ASSERT( sr.read(nullptr, 0).empty() ); + } testNull(); testBoolean(); testString();