Don't free m_szFileString twice.

Must use delete[] x when x was allocated as an array.

No need to check for NULL; "delete NULL" is always OK. (http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.7)

Don't depend on the compiler having old-style for scoping rules.

Remove extra iCurValueIndex/iCurParamIndex.
This commit is contained in:
Glenn Maynard
2002-08-20 01:27:42 +00:00
parent 7236c5bb91
commit 4e2993f370
+5 -12
View File
@@ -21,16 +21,12 @@ MsdFile::MsdFile()
MsdFile::~MsdFile()
{
if( m_szFileString )
delete m_szFileString;
delete [] m_szFileString;
}
//returns true if successful, false otherwise
bool MsdFile::ReadFile( CString sNewPath )
{
if( m_szFileString )
delete m_szFileString;
// Get file size in bytes
HANDLE hFile = CreateFile(
sNewPath, // pointer to name of the file
@@ -46,8 +42,7 @@ bool MsdFile::ReadFile( CString sNewPath )
CloseHandle( hFile );
// allocate a string to hold the file
if( m_szFileString )
delete m_szFileString;
delete [] m_szFileString;
m_szFileString = new char[iBufferSize];
FILE* fp = fopen(sNewPath, "r");
@@ -59,8 +54,9 @@ bool MsdFile::ReadFile( CString sNewPath )
ASSERT( iBufferSize > iBytesRead );
m_iNumValues = 0;
for( int i=0; i<iBytesRead; i++ )
int i;
for( i=0; i<iBytesRead; i++ )
{
switch( m_szFileString[i] )
{
@@ -109,9 +105,6 @@ bool MsdFile::ReadFile( CString sNewPath )
m_szFileString[i] = '\0';
int iCurValueIndex = m_iNumValues-1;
int iCurParamIndex = m_iNumParams[iCurValueIndex]-1;
for( i=0; i<m_iNumValues; i++ )
{
for( int j=0; j<m_iNumParams[i]; j++ )