Skip to content

Commit

Permalink
Fix itsNextName not clearing when not found
Browse files Browse the repository at this point in the history
An issue exists when loading vectors of objects where, if the last nvp of
the previous object does not exist in the json file, the itsNextName
variable within the json serializer is not cleared. This causes the vector
serializer to search for that name next (when it should be searching for a
nameless object.) The json serializer then throws during the named search.

Mild reworking of itsNextName solution
  • Loading branch information
gheckman-gadova authored and AzothAmmo committed Sep 21, 2021
1 parent f8338db commit af0700e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions include/cereal/archives/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,18 +564,20 @@ namespace cereal
@throws Exception if an expectedName is given and not found */
inline void search()
{
// store pointer to itsNextName locally and reset to nullptr in case search() throws
auto localNextName = itsNextName;
itsNextName = nullptr;

// The name an NVP provided with setNextName()
if( itsNextName )
if( localNextName )
{
// The actual name of the current node
auto const actualName = itsIteratorStack.back().name();

// Do a search if we don't see a name coming up, or if the names don't match
if( !actualName || std::strcmp( itsNextName, actualName ) != 0 )
itsIteratorStack.back().search( itsNextName );
if( !actualName || std::strcmp( localNextName, actualName ) != 0 )
itsIteratorStack.back().search( localNextName );
}

itsNextName = nullptr;
}

public:
Expand Down

0 comments on commit af0700e

Please sign in to comment.