Fix some crashes (issue #1076)

This commit is contained in:
Abs62 2019-01-17 17:53:13 +03:00
parent 6d46fd1529
commit 04d9dc43f6
9 changed files with 53 additions and 20 deletions

3
bgl.cc
View file

@ -289,11 +289,14 @@ namespace
size_t len = idx.read< uint32_t >();
if( len )
{
vector< char > nameBuf( len );
idx.read( &nameBuf.front(), len );
dictionaryName = string( &nameBuf.front(), len );
}
// Initialize the index

View file

@ -161,8 +161,11 @@ DictdDictionary::DictdDictionary( string const & id,
idx.seek( sizeof( idxHeader ) );
vector< char > dName( idx.read< uint32_t >() );
if( dName.size() > 0 )
{
idx.read( &dName.front(), dName.size() );
dictionaryName = string( &dName.front(), dName.size() );
}
// Open the .dict file

6
dsl.cc
View file

@ -310,12 +310,18 @@ DslDictionary::DslDictionary( string const & id,
idx.seek( sizeof( idxHeader ) );
vector< char > dName( idx.read< uint32_t >() );
if( dName.size() > 0 )
{
idx.read( &dName.front(), dName.size() );
dictionaryName = string( &dName.front(), dName.size() );
}
vector< char > sName( idx.read< uint32_t >() );
if( sName.size() > 0 )
{
idx.read( &sName.front(), sName.size() );
preferredSoundDictionary = string( &sName.front(), sName.size() );
}
// Everything else would be done in deferred init
}

View file

@ -204,8 +204,11 @@ EpwingDictionary::EpwingDictionary( string const & id,
{
vector< char > data( idxHeader.nameSize );
idx.seek( sizeof( idxHeader ) );
if( data.size() > 0 )
{
idx.read( &data.front(), idxHeader.nameSize );
bookName = string( &data.front(), idxHeader.nameSize );
}
// Initialize eBook

3
gls.cc
View file

@ -549,8 +549,11 @@ GlsDictionary::GlsDictionary( string const & id,
idx.seek( sizeof( idxHeader ) );
vector< char > dName( idx.read< uint32_t >() );
if( dName.size() > 0 )
{
idx.read( &dName.front(), dName.size() );
dictionaryName = string( &dName.front(), dName.size() );
}
// Initialize the index

6
mdx.cc
View file

@ -303,14 +303,20 @@ MdxDictionary::MdxDictionary( string const & id, string const & indexFile,
idx.seek( sizeof( idxHeader ) );
size_t len = idx.read< uint32_t >();
vector< char > buf( len );
if( len > 0 )
{
idx.read( &buf.front(), len );
dictionaryName = string( &buf.front(), len );
}
// then read the dictionary's encoding
len = idx.read< uint32_t >();
if( len > 0 )
{
buf.resize( len );
idx.read( &buf.front(), len );
encoding = string( &buf.front(), len );
}
dictFile.setFileName( QString::fromUtf8( dictionaryFiles[ 0 ].c_str() ) );
dictFile.open( QIODevice::ReadOnly );

View file

@ -212,8 +212,11 @@ SdictDictionary::SdictDictionary( string const & id,
idx.seek( sizeof( idxHeader ) );
vector< char > dName( idx.read< uint32_t >() );
if( dName.size() > 0 )
{
idx.read( &dName.front(), dName.size() );
dictionaryName = string( &dName.front(), dName.size() );
}
// Initialize the index

View file

@ -312,6 +312,9 @@ void StardictDictionary::loadIcon() throw()
string StardictDictionary::loadString( size_t size )
{
if( size == 0 )
return string();
vector< char > data( size );
idx.read( &data.front(), data.size() );

View file

@ -133,6 +133,9 @@ long decode( char const * in_, size_t inSize, wchar * out_ )
string encode( wstring const & in ) throw()
{
if( in.size() == 0 )
return string();
std::vector< char > buffer( in.size() * 4 );
return string( &buffer.front(),