Fix crash introduced in 605cdcb5.

This commit is contained in:
Bartosz Taudul 2024-09-24 17:15:43 +02:00
parent f6882e2a5d
commit 9b9a883d07
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 8 additions and 5 deletions

View File

@ -9,8 +9,9 @@ SourceContents::SourceContents()
: m_file( nullptr ) : m_file( nullptr )
, m_fileStringIdx( 0 ) , m_fileStringIdx( 0 )
, m_data( nullptr ) , m_data( nullptr )
, m_dataBuf( nullptr )
, m_dataSize( 0 ) , m_dataSize( 0 )
, m_dataBuf( nullptr )
, m_dataBufSize( 0 )
{ {
} }
@ -44,14 +45,15 @@ void SourceContents::Parse( const char* fileName, const Worker& worker, const Vi
fseek( f, 0, SEEK_END ); fseek( f, 0, SEEK_END );
sz = ftell( f ); sz = ftell( f );
fseek( f, 0, SEEK_SET ); fseek( f, 0, SEEK_SET );
if( sz > m_dataSize ) if( sz > m_dataBufSize )
{ {
delete[] m_dataBuf; delete[] m_dataBuf;
m_dataBuf = new char[sz]; m_dataBuf = new char[sz];
m_dataSize = sz; m_dataBufSize = sz;
} }
fread( m_dataBuf, 1, sz, f ); fread( m_dataBuf, 1, sz, f );
m_data = m_dataBuf; m_data = m_dataBuf;
m_dataSize = sz;
fclose( f ); fclose( f );
} }
else else
@ -73,7 +75,6 @@ void SourceContents::Parse( const char* source )
m_file = nullptr; m_file = nullptr;
m_fileStringIdx = 0; m_fileStringIdx = 0;
m_data = source; m_data = source;
m_dataBuf = nullptr;
m_dataSize = len; m_dataSize = len;
Tokenize( source, len ); Tokenize( source, len );
} }

View File

@ -38,9 +38,11 @@ private:
uint32_t m_fileStringIdx; uint32_t m_fileStringIdx;
const char* m_data; const char* m_data;
char* m_dataBuf;
size_t m_dataSize; size_t m_dataSize;
char* m_dataBuf;
size_t m_dataBufSize;
std::vector<Tokenizer::Line> m_lines; std::vector<Tokenizer::Line> m_lines;
}; };