Hook up source location overflow failures.

Note: not tested. Expect some off-by-one bugs. Control flow may fail. Oh no.
This commit is contained in:
Bartosz Taudul 2023-12-31 13:05:44 +01:00
parent 54ee77026f
commit 586c6bf166
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -3326,6 +3326,12 @@ void Worker::NewSourceLocation( uint64_t ptr )
{ {
static const SourceLocation emptySourceLocation = {}; static const SourceLocation emptySourceLocation = {};
if( m_data.sourceLocation.size() > std::numeric_limits<int16_t>::max() )
{
SourceLocationOverflowFailure();
return;
}
m_data.sourceLocation.emplace( ptr, emptySourceLocation ); m_data.sourceLocation.emplace( ptr, emptySourceLocation );
m_pendingSourceLocation++; m_pendingSourceLocation++;
m_sourceLocationQueue.push_back( ptr ); m_sourceLocationQueue.push_back( ptr );
@ -3708,6 +3714,11 @@ void Worker::AddSourceLocationPayload( const char* data, size_t sz )
auto slptr = m_slab.Alloc<SourceLocation>(); auto slptr = m_slab.Alloc<SourceLocation>();
memcpy( slptr, &srcloc, sizeof( srcloc ) ); memcpy( slptr, &srcloc, sizeof( srcloc ) );
uint32_t idx = m_data.sourceLocationPayload.size(); uint32_t idx = m_data.sourceLocationPayload.size();
if( idx+1 > std::numeric_limits<int16_t>::max() )
{
SourceLocationOverflowFailure();
return;
}
m_data.sourceLocationPayloadMap.emplace( slptr, idx ); m_data.sourceLocationPayloadMap.emplace( slptr, idx );
m_pendingSourceLocationPayload = -int16_t( idx + 1 ); m_pendingSourceLocationPayload = -int16_t( idx + 1 );
m_data.sourceLocationPayload.push_back( slptr ); m_data.sourceLocationPayload.push_back( slptr );