Skip to content

Commit 6d2b895

Browse files
int-72hReplayCoding
authored andcommitted
fixed segfault on KeyValues::WriteAsBinary, fixing inspects
1 parent e982d94 commit 6d2b895

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/public/tier1/KeyValues.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class KeyValues
213213

214214
void RecursiveSaveToFile( CUtlBuffer& buf, int indentLevel, bool sortKeys = false, bool bAllowEmptyString = false );
215215

216-
bool WriteAsBinary( CUtlBuffer &buffer );
216+
bool WriteAsBinary( CUtlBuffer &buffer, bool recurse = false );
217217
bool ReadAsBinary( CUtlBuffer &buffer, int nStackDepth = 0 );
218218

219219
// Allocate & create a new copy of the keys

src/tier1/KeyValues.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define _wtoi(arg) wcstol(arg, NULL, 10)
1515
#define _wtoi64(arg) wcstoll(arg, NULL, 10)
1616
#endif
17-
1817
#include <KeyValues.h>
1918
#include "filesystem.h"
2019
#include <vstdlib/IKeyValuesSystem.h>
@@ -2583,7 +2582,7 @@ void KeyValues::RecursiveLoadFromBuffer( char const *resourceName, CUtlBuffer &b
25832582

25842583

25852584
// writes KeyValue as binary data to buffer
2586-
bool KeyValues::WriteAsBinary( CUtlBuffer &buffer )
2585+
bool KeyValues::WriteAsBinary( CUtlBuffer &buffer,bool recurse)
25872586
{
25882587
if ( buffer.IsText() ) // must be a binary buffer
25892588
return false;
@@ -2597,6 +2596,9 @@ bool KeyValues::WriteAsBinary( CUtlBuffer &buffer )
25972596
for ( KeyValues *dat = this; dat != NULL; dat = dat->m_pPeer )
25982597
{
25992598
// write type
2599+
if(recurse){
2600+
break; //HACK: no idea how this works, put in as a debugging tool, but seems to fix the issue. Stops segfaulting on inspecting on Linux. (int)
2601+
}
26002602
buffer.PutUnsignedChar( dat->m_iDataType );
26012603

26022604
// write name
@@ -2607,7 +2609,7 @@ bool KeyValues::WriteAsBinary( CUtlBuffer &buffer )
26072609
{
26082610
case TYPE_NONE:
26092611
{
2610-
dat->m_pSub->WriteAsBinary( buffer );
2612+
dat->m_pSub->WriteAsBinary( buffer,true );
26112613
break;
26122614
}
26132615
case TYPE_STRING:
@@ -2695,7 +2697,6 @@ bool KeyValues::ReadAsBinary( CUtlBuffer &buffer, int nStackDepth )
26952697
{
26962698
if ( type == TYPE_NUMTYPES )
26972699
break; // no more peers
2698-
26992700
dat->m_iDataType = type;
27002701

27012702
{

0 commit comments

Comments
 (0)