From ab98efe595b09ca44fc6c9283e7aedcdb4f2dd9a Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 11 May 2012 01:10:40 +0200 Subject: WINTERMUTE: Make ScEngine use Common::String to avoid some double-frees. --- engines/wintermute/scriptables/ScEngine.cpp | 8 ++++---- engines/wintermute/scriptables/ScEngine.h | 12 ++++-------- 2 files changed, 8 insertions(+), 12 deletions(-) (limited to 'engines/wintermute') diff --git a/engines/wintermute/scriptables/ScEngine.cpp b/engines/wintermute/scriptables/ScEngine.cpp index 20716cfd04..0b19542beb 100644 --- a/engines/wintermute/scriptables/ScEngine.cpp +++ b/engines/wintermute/scriptables/ScEngine.cpp @@ -271,7 +271,7 @@ byte *CScEngine::GetCompiledScript(char *Filename, uint32 *OutSize, bool IgnoreC // is script in cache? if (!IgnoreCache) { for (i = 0; i < MAX_CACHED_SCRIPTS; i++) { - if (_cachedScripts[i] && scumm_stricmp(_cachedScripts[i]->_filename, Filename) == 0) { + if (_cachedScripts[i] && scumm_stricmp(_cachedScripts[i]->_filename.c_str(), Filename) == 0) { _cachedScripts[i]->_timestamp = CBPlatform::GetTime(); *OutSize = _cachedScripts[i]->_size; return _cachedScripts[i]->_buffer; @@ -667,7 +667,7 @@ HRESULT CScEngine::AddBreakpoint(char *ScriptFilename, int Line) { CScBreakpoint *Bp = NULL; for (int i = 0; i < _breakpoints.GetSize(); i++) { - if (scumm_stricmp(_breakpoints[i]->_filename, ScriptFilename) == 0) { + if (scumm_stricmp(_breakpoints[i]->_filename.c_str(), ScriptFilename) == 0) { Bp = _breakpoints[i]; break; } @@ -693,7 +693,7 @@ HRESULT CScEngine::RemoveBreakpoint(char *ScriptFilename, int Line) { if (!Game->GetDebugMgr()->_enabled) return S_OK; for (int i = 0; i < _breakpoints.GetSize(); i++) { - if (scumm_stricmp(_breakpoints[i]->_filename, ScriptFilename) == 0) { + if (scumm_stricmp(_breakpoints[i]->_filename.c_str(), ScriptFilename) == 0) { for (int j = 0; j < _breakpoints[i]->_lines.GetSize(); j++) { if (_breakpoints[i]->_lines[j] == Line) { _breakpoints[i]->_lines.RemoveAt(j); @@ -730,7 +730,7 @@ HRESULT CScEngine::RefreshScriptBreakpoints(CScScript *Script) { if (!Script || !Script->_filename) return E_FAIL; for (int i = 0; i < _breakpoints.GetSize(); i++) { - if (scumm_stricmp(_breakpoints[i]->_filename, Script->_filename) == 0) { + if (scumm_stricmp(_breakpoints[i]->_filename.c_str(), Script->_filename) == 0) { Script->_breakpoints.Copy(_breakpoints[i]->_lines); return S_OK; } diff --git a/engines/wintermute/scriptables/ScEngine.h b/engines/wintermute/scriptables/ScEngine.h index 7be147b39e..7ca9ec0771 100644 --- a/engines/wintermute/scriptables/ScEngine.h +++ b/engines/wintermute/scriptables/ScEngine.h @@ -62,34 +62,30 @@ public: _buffer = new byte[Size]; if (_buffer) memcpy(_buffer, Buffer, Size); _size = Size; - _filename = new char[strlen(Filename) + 1]; - if (_filename) strcpy(_filename, Filename); + _filename = Filename; }; ~CScCachedScript() { if (_buffer) delete [] _buffer; - if (_filename) delete [] _filename; }; uint32 _timestamp; byte *_buffer; uint32 _size; - char *_filename; + Common::String _filename; }; class CScBreakpoint { public: CScBreakpoint(const char *Filename) { - _filename = NULL; - CBUtils::SetString(&_filename, Filename); + _filename = Filename; } ~CScBreakpoint() { - if (_filename) delete [] _filename; _lines.RemoveAll(); } - char *_filename; + Common::String _filename; CBArray _lines; }; -- cgit v1.2.3