1
0
mirror of https://github.com/wolfpld/tracy synced 2025-05-01 05:03:53 +00:00

Don't depend on zero-termination of source code.

This commit is contained in:
Bartosz Taudul 2020-05-23 17:07:23 +02:00
parent d3b60f913d
commit 45a9878193
2 changed files with 4 additions and 6 deletions

View File

@ -457,11 +457,10 @@ void SourceView::ParseSource( const char* fileName, const Worker& worker, const
if( sz > m_dataSize ) if( sz > m_dataSize )
{ {
delete[] m_dataBuf; delete[] m_dataBuf;
m_dataBuf = new char[sz+1]; m_dataBuf = new char[sz];
m_dataSize = sz; m_dataSize = sz;
} }
fread( m_dataBuf, 1, sz, f ); fread( m_dataBuf, 1, sz, f );
m_dataBuf[sz] = '\0';
m_data = m_dataBuf; m_data = m_dataBuf;
fclose( f ); fclose( f );
} }
@ -483,7 +482,7 @@ void SourceView::ParseSource( const char* fileName, const Worker& worker, const
end++; end++;
if( *end == '\n' ) end++; if( *end == '\n' ) end++;
} }
if( *end == '\0' ) break; if( end - m_data == sz ) break;
txt = end; txt = end;
} }
} }

View File

@ -7404,11 +7404,10 @@ void Worker::CacheSource( const StringRef& str )
fseek( f, 0, SEEK_END ); fseek( f, 0, SEEK_END );
const auto sz = ftell( f ); const auto sz = ftell( f );
fseek( f, 0, SEEK_SET ); fseek( f, 0, SEEK_SET );
auto src = (char*)m_slab.AllocBig( sz+1 ); auto src = (char*)m_slab.AllocBig( sz );
fread( src, 1, sz, f ); fread( src, 1, sz, f );
src[sz] = '\0';
fclose( f ); fclose( f );
m_data.sourceFileCache.emplace( file, MemoryBlock{ src, uint32_t( sz+1 ) } ); m_data.sourceFileCache.emplace( file, MemoryBlock{ src, uint32_t( sz ) } );
} }
} }
} }