mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
Fix some crashes (issue #1076)
This commit is contained in:
parent
6d46fd1529
commit
04d9dc43f6
9
bgl.cc
9
bgl.cc
|
@ -289,11 +289,14 @@ namespace
|
|||
|
||||
size_t len = idx.read< uint32_t >();
|
||||
|
||||
vector< char > nameBuf( len );
|
||||
if( len )
|
||||
{
|
||||
vector< char > nameBuf( len );
|
||||
|
||||
idx.read( &nameBuf.front(), len );
|
||||
idx.read( &nameBuf.front(), len );
|
||||
|
||||
dictionaryName = string( &nameBuf.front(), len );
|
||||
dictionaryName = string( &nameBuf.front(), len );
|
||||
}
|
||||
|
||||
// Initialize the index
|
||||
|
||||
|
|
|
@ -161,8 +161,11 @@ DictdDictionary::DictdDictionary( string const & id,
|
|||
idx.seek( sizeof( idxHeader ) );
|
||||
|
||||
vector< char > dName( idx.read< uint32_t >() );
|
||||
idx.read( &dName.front(), dName.size() );
|
||||
dictionaryName = string( &dName.front(), dName.size() );
|
||||
if( dName.size() > 0 )
|
||||
{
|
||||
idx.read( &dName.front(), dName.size() );
|
||||
dictionaryName = string( &dName.front(), dName.size() );
|
||||
}
|
||||
|
||||
// Open the .dict file
|
||||
|
||||
|
|
14
dsl.cc
14
dsl.cc
|
@ -310,12 +310,18 @@ DslDictionary::DslDictionary( string const & id,
|
|||
idx.seek( sizeof( idxHeader ) );
|
||||
|
||||
vector< char > dName( idx.read< uint32_t >() );
|
||||
idx.read( &dName.front(), dName.size() );
|
||||
dictionaryName = string( &dName.front(), dName.size() );
|
||||
if( dName.size() > 0 )
|
||||
{
|
||||
idx.read( &dName.front(), dName.size() );
|
||||
dictionaryName = string( &dName.front(), dName.size() );
|
||||
}
|
||||
|
||||
vector< char > sName( idx.read< uint32_t >() );
|
||||
idx.read( &sName.front(), sName.size() );
|
||||
preferredSoundDictionary = string( &sName.front(), sName.size() );
|
||||
if( sName.size() > 0 )
|
||||
{
|
||||
idx.read( &sName.front(), sName.size() );
|
||||
preferredSoundDictionary = string( &sName.front(), sName.size() );
|
||||
}
|
||||
|
||||
// Everything else would be done in deferred init
|
||||
}
|
||||
|
|
|
@ -204,8 +204,11 @@ EpwingDictionary::EpwingDictionary( string const & id,
|
|||
{
|
||||
vector< char > data( idxHeader.nameSize );
|
||||
idx.seek( sizeof( idxHeader ) );
|
||||
idx.read( &data.front(), idxHeader.nameSize );
|
||||
bookName = string( &data.front(), idxHeader.nameSize );
|
||||
if( data.size() > 0 )
|
||||
{
|
||||
idx.read( &data.front(), idxHeader.nameSize );
|
||||
bookName = string( &data.front(), idxHeader.nameSize );
|
||||
}
|
||||
|
||||
// Initialize eBook
|
||||
|
||||
|
|
7
gls.cc
7
gls.cc
|
@ -549,8 +549,11 @@ GlsDictionary::GlsDictionary( string const & id,
|
|||
idx.seek( sizeof( idxHeader ) );
|
||||
|
||||
vector< char > dName( idx.read< uint32_t >() );
|
||||
idx.read( &dName.front(), dName.size() );
|
||||
dictionaryName = string( &dName.front(), dName.size() );
|
||||
if( dName.size() > 0 )
|
||||
{
|
||||
idx.read( &dName.front(), dName.size() );
|
||||
dictionaryName = string( &dName.front(), dName.size() );
|
||||
}
|
||||
|
||||
// Initialize the index
|
||||
|
||||
|
|
16
mdx.cc
16
mdx.cc
|
@ -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 );
|
||||
idx.read( &buf.front(), len );
|
||||
dictionaryName = string( &buf.front(), 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 >();
|
||||
buf.resize( len );
|
||||
idx.read( &buf.front(), len );
|
||||
encoding = string( &buf.front(), len );
|
||||
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 );
|
||||
|
|
7
sdict.cc
7
sdict.cc
|
@ -212,8 +212,11 @@ SdictDictionary::SdictDictionary( string const & id,
|
|||
|
||||
idx.seek( sizeof( idxHeader ) );
|
||||
vector< char > dName( idx.read< uint32_t >() );
|
||||
idx.read( &dName.front(), dName.size() );
|
||||
dictionaryName = string( &dName.front(), dName.size() );
|
||||
if( dName.size() > 0 )
|
||||
{
|
||||
idx.read( &dName.front(), dName.size() );
|
||||
dictionaryName = string( &dName.front(), dName.size() );
|
||||
}
|
||||
|
||||
// Initialize the index
|
||||
|
||||
|
|
|
@ -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() );
|
||||
|
|
Loading…
Reference in a new issue