From 100ce95f14e6e597fa769021af3914ecc9301d59 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Tue, 22 Nov 2005 21:14:48 +0000 Subject: [PATCH] don't pass DISPLAY_OPT as a pointer to avoid NULL pointer deref --- stepmania/src/Bookkeeper.cpp | 2 +- stepmania/src/CatalogXml.cpp | 2 +- stepmania/src/Profile.cpp | 2 +- stepmania/src/XmlFile.cpp | 47 ++++++++++++++++++------------------ stepmania/src/XmlFile.h | 8 +++--- 5 files changed, 31 insertions(+), 30 deletions(-) diff --git a/stepmania/src/Bookkeeper.cpp b/stepmania/src/Bookkeeper.cpp index e38b435b14..78d4c4d838 100644 --- a/stepmania/src/Bookkeeper.cpp +++ b/stepmania/src/Bookkeeper.cpp @@ -140,7 +140,7 @@ void Bookkeeper::WriteToDisk() DISP_OPT opt; XNode *xml = CreateNode(); - xml->SaveToFile( f, &opt ); + xml->SaveToFile( f, opt ); delete xml; } diff --git a/stepmania/src/CatalogXml.cpp b/stepmania/src/CatalogXml.cpp index 19cbc2d50b..ff55464033 100644 --- a/stepmania/src/CatalogXml.cpp +++ b/stepmania/src/CatalogXml.cpp @@ -373,7 +373,7 @@ void SaveCatalogXml( LoadingWindow *loading_window ) DISP_OPT opts; opts.stylesheet = CATALOG_XSL; opts.write_tabs = false; - xml.SaveToFile(fn, &opts); + xml.SaveToFile(fn, opts); LOG->Trace( "Done." ); } diff --git a/stepmania/src/Profile.cpp b/stepmania/src/Profile.cpp index cd98f7b916..bea001a86f 100644 --- a/stepmania/src/Profile.cpp +++ b/stepmania/src/Profile.cpp @@ -959,7 +959,7 @@ bool Profile::SaveStatsXmlToDir( CString sDir, bool bSignData ) const DISP_OPT opts; opts.stylesheet = STATS_XSL; opts.write_tabs = false; - bool bSaved = xml->SaveToFile(fn, &opts); + bool bSaved = xml->SaveToFile( fn, opts ); SAFE_DELETE( xml ); diff --git a/stepmania/src/XmlFile.cpp b/stepmania/src/XmlFile.cpp index 81ceb3ae7b..4423165d4b 100644 --- a/stepmania/src/XmlFile.cpp +++ b/stepmania/src/XmlFile.cpp @@ -438,25 +438,25 @@ unsigned XNode::Load( const CString &xml, PARSEINFO *pi, unsigned iOffset ) // Desc : convert plain xml text from parsed xml attirbute // Return : converted plain string -bool XNode::GetAttrXML( RageFileBasic &f, DISP_OPT *opt, const CString &sName, const CString &sValue ) const +bool XNode::GetAttrXML( RageFileBasic &f, DISP_OPT &opt, const CString &sName, const CString &sValue ) const { CString s(sValue); - if( opt && opt->reference_value ) + if( opt.reference_value ) ReplaceEntityText( s, g_mapCharsToEntities ); return f.Write(sName + "='" + s + "' ") != -1; } // Desc : convert plain xml text from parsed xml node // Return : converted plain string -bool XNode::GetXML( RageFileBasic &f, DISP_OPT *opt ) const +bool XNode::GetXML( RageFileBasic &f, DISP_OPT &opt ) const { // tab - if( opt && opt->newline ) + if( opt.newline ) { if( f.Write("\r\n") == -1 ) return false; - if( opt->write_tabs ) - for( int i = 0 ; i < opt->tab_base ; i++) + if( opt.write_tabs ) + for( int i = 0 ; i < opt.tab_base ; i++) if( f.Write("\t") == -1 ) return false; } @@ -485,9 +485,9 @@ bool XNode::GetXML( RageFileBasic &f, DISP_OPT *opt ) const if( f.Write(">") == -1 ) return false; - if( opt && opt->newline && !m_childs.empty() ) + if( opt.newline && !m_childs.empty() ) { - opt->tab_base++; + opt.tab_base++; } FOREACH_CONST_Child( this, p ) @@ -497,40 +497,40 @@ bool XNode::GetXML( RageFileBasic &f, DISP_OPT *opt ) const // Text Value if( !m_sValue.empty() ) { - if( opt && opt->newline && !m_childs.empty() ) + if( opt.newline && !m_childs.empty() ) { - if( opt && opt->newline ) + if( opt.newline ) if( f.Write("\r\n") == -1 ) return false; - if( opt->write_tabs ) - for( int i = 0 ; i < opt->tab_base ; i++) + if( opt.write_tabs ) + for( int i = 0 ; i < opt.tab_base ; i++) if( f.Write("\t") == -1 ) return false; } CString s( m_sValue ); - if( opt && opt->reference_value ) + if( opt.reference_value ) ReplaceEntityText( s, g_mapCharsToEntities ); if( f.Write(s) == -1 ) return false; } // CloseTag - if( opt && opt->newline && !m_childs.empty() ) + if( opt.newline && !m_childs.empty() ) { if( f.Write("\r\n") == -1 ) return false; - if( opt->write_tabs ) - for( int i = 0 ; i < opt->tab_base-1 ; i++) + if( opt.write_tabs ) + for( int i = 0 ; i < opt.tab_base-1 ; i++) if( f.Write("\t") == -1 ) return false; } if( f.Write("") == -1 ) return false; - if( opt && opt->newline ) + if( opt.newline ) { if( !m_childs.empty() ) - opt->tab_base--; + opt.tab_base--; } } return true; @@ -541,7 +541,8 @@ bool XNode::GetXML( RageFileBasic &f, DISP_OPT *opt ) const CString XNode::GetXML() const { RageFileObjMem f; - GetXML( f, NULL ); + DISP_OPT opt; + GetXML( f, opt ); return f.GetString(); } @@ -697,11 +698,11 @@ error: return false; } -bool XNode::SaveToFile( RageFileBasic &f, DISP_OPT *opt ) const +bool XNode::SaveToFile( RageFileBasic &f, DISP_OPT &opt ) const { f.PutLine( "" ); - if( !opt->stylesheet.empty() ) - f.PutLine( "stylesheet + "\"?>" ); + if( !opt.stylesheet.empty() ) + f.PutLine( "" ); if( !this->GetXML(f, opt) ) return false; if( f.Flush() == -1 ) @@ -709,7 +710,7 @@ bool XNode::SaveToFile( RageFileBasic &f, DISP_OPT *opt ) const return true; } -bool XNode::SaveToFile( const CString &sFile, DISP_OPT *opt ) const +bool XNode::SaveToFile( const CString &sFile, DISP_OPT &opt ) const { RageFile f; if( !f.Open(sFile, RageFile::WRITE) ) diff --git a/stepmania/src/XmlFile.h b/stepmania/src/XmlFile.h index 1dfe922797..f246f811fe 100644 --- a/stepmania/src/XmlFile.h +++ b/stepmania/src/XmlFile.h @@ -102,14 +102,14 @@ struct XNode // Load/Save XML unsigned Load( const CString &sXml, PARSEINFO *pi, unsigned iOffset = 0 ); unsigned LoadAttributes( const CString &sAttrs, PARSEINFO *pi, unsigned iOffset ); - bool GetXML( RageFileBasic &f, DISP_OPT *opt ) const; - bool GetAttrXML( RageFileBasic &f, DISP_OPT *opt, const CString &sName, const CString &sValue ) const; + bool GetXML( RageFileBasic &f, DISP_OPT &opt ) const; + bool GetAttrXML( RageFileBasic &f, DISP_OPT &opt, const CString &sName, const CString &sValue ) const; CString GetXML() const; bool LoadFromFile( const CString &sFile ); bool LoadFromFile( RageFileBasic &f ); - bool SaveToFile( const CString &sFile, DISP_OPT *opt ) const; - bool SaveToFile( RageFileBasic &f, DISP_OPT *opt ) const; + bool SaveToFile( const CString &sFile, DISP_OPT &opt ) const; + bool SaveToFile( RageFileBasic &f, DISP_OPT &opt ) const; // in own attribute list const CString *GetAttr( const CString &sAttrName ) const;