Throw exception when trying to open unsupported dump version.

This commit is contained in:
Bartosz Taudul 2018-04-21 14:18:13 +02:00
parent 3793a37b2b
commit 36efe96e9d
2 changed files with 16 additions and 3 deletions

View File

@ -19,14 +19,15 @@
namespace tracy
{
static const uint8_t FileHeader[8] { 't', 'r', 'a', 'c', 'y', 0, 3, 0 };
enum { FileHeaderMagic = 5 };
static constexpr int FileVersion( uint8_t h5, uint8_t h6, uint8_t h7 )
{
return ( h5 << 16 ) | ( h6 << 8 ) | h7;
}
static const uint8_t FileHeader[8] { 't', 'r', 'a', 'c', 'y', 0, 3, 0 };
enum { FileHeaderMagic = 5 };
static const int CurrentVersion = FileVersion( FileHeader[FileHeaderMagic], FileHeader[FileHeaderMagic+1], FileHeader[FileHeaderMagic+2] );
Worker::Worker( const char* addr )
: m_addr( addr )
, m_connected( false )
@ -61,6 +62,11 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
if( memcmp( FileHeader, hdr, FileHeaderMagic ) == 0 )
{
fileVer = FileVersion( hdr[FileHeaderMagic], hdr[FileHeaderMagic+1], hdr[FileHeaderMagic+2] );
if( fileVer > CurrentVersion )
{
throw UnsupportedVersion( fileVer );
}
f.Read( &m_delay, sizeof( m_delay ) );
}
else

View File

@ -4,6 +4,7 @@
#include <atomic>
#include <limits>
#include <map>
#include <stdexcept>
#include <string>
#include <thread>
#include <vector>
@ -37,6 +38,12 @@ namespace EventType
};
}
struct UnsupportedVersion : public std::exception
{
UnsupportedVersion( int version ) : version( version ) {}
int version;
};
class Worker
{
#pragma pack( 1 )