mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 04:24:09 +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 >();
|
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
|
// Initialize the index
|
||||||
|
|
||||||
|
|
|
@ -161,8 +161,11 @@ DictdDictionary::DictdDictionary( string const & id,
|
||||||
idx.seek( sizeof( idxHeader ) );
|
idx.seek( sizeof( idxHeader ) );
|
||||||
|
|
||||||
vector< char > dName( idx.read< uint32_t >() );
|
vector< char > dName( idx.read< uint32_t >() );
|
||||||
idx.read( &dName.front(), dName.size() );
|
if( dName.size() > 0 )
|
||||||
dictionaryName = string( &dName.front(), dName.size() );
|
{
|
||||||
|
idx.read( &dName.front(), dName.size() );
|
||||||
|
dictionaryName = string( &dName.front(), dName.size() );
|
||||||
|
}
|
||||||
|
|
||||||
// Open the .dict file
|
// Open the .dict file
|
||||||
|
|
||||||
|
|
14
dsl.cc
14
dsl.cc
|
@ -310,12 +310,18 @@ DslDictionary::DslDictionary( string const & id,
|
||||||
idx.seek( sizeof( idxHeader ) );
|
idx.seek( sizeof( idxHeader ) );
|
||||||
|
|
||||||
vector< char > dName( idx.read< uint32_t >() );
|
vector< char > dName( idx.read< uint32_t >() );
|
||||||
idx.read( &dName.front(), dName.size() );
|
if( dName.size() > 0 )
|
||||||
dictionaryName = string( &dName.front(), dName.size() );
|
{
|
||||||
|
idx.read( &dName.front(), dName.size() );
|
||||||
|
dictionaryName = string( &dName.front(), dName.size() );
|
||||||
|
}
|
||||||
|
|
||||||
vector< char > sName( idx.read< uint32_t >() );
|
vector< char > sName( idx.read< uint32_t >() );
|
||||||
idx.read( &sName.front(), sName.size() );
|
if( sName.size() > 0 )
|
||||||
preferredSoundDictionary = string( &sName.front(), sName.size() );
|
{
|
||||||
|
idx.read( &sName.front(), sName.size() );
|
||||||
|
preferredSoundDictionary = string( &sName.front(), sName.size() );
|
||||||
|
}
|
||||||
|
|
||||||
// Everything else would be done in deferred init
|
// Everything else would be done in deferred init
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,8 +204,11 @@ EpwingDictionary::EpwingDictionary( string const & id,
|
||||||
{
|
{
|
||||||
vector< char > data( idxHeader.nameSize );
|
vector< char > data( idxHeader.nameSize );
|
||||||
idx.seek( sizeof( idxHeader ) );
|
idx.seek( sizeof( idxHeader ) );
|
||||||
idx.read( &data.front(), idxHeader.nameSize );
|
if( data.size() > 0 )
|
||||||
bookName = string( &data.front(), idxHeader.nameSize );
|
{
|
||||||
|
idx.read( &data.front(), idxHeader.nameSize );
|
||||||
|
bookName = string( &data.front(), idxHeader.nameSize );
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize eBook
|
// Initialize eBook
|
||||||
|
|
||||||
|
|
7
gls.cc
7
gls.cc
|
@ -549,8 +549,11 @@ GlsDictionary::GlsDictionary( string const & id,
|
||||||
idx.seek( sizeof( idxHeader ) );
|
idx.seek( sizeof( idxHeader ) );
|
||||||
|
|
||||||
vector< char > dName( idx.read< uint32_t >() );
|
vector< char > dName( idx.read< uint32_t >() );
|
||||||
idx.read( &dName.front(), dName.size() );
|
if( dName.size() > 0 )
|
||||||
dictionaryName = string( &dName.front(), dName.size() );
|
{
|
||||||
|
idx.read( &dName.front(), dName.size() );
|
||||||
|
dictionaryName = string( &dName.front(), dName.size() );
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize the index
|
// 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 ) );
|
idx.seek( sizeof( idxHeader ) );
|
||||||
size_t len = idx.read< uint32_t >();
|
size_t len = idx.read< uint32_t >();
|
||||||
vector< char > buf( len );
|
vector< char > buf( len );
|
||||||
idx.read( &buf.front(), len );
|
if( len > 0 )
|
||||||
dictionaryName = string( &buf.front(), len );
|
{
|
||||||
|
idx.read( &buf.front(), len );
|
||||||
|
dictionaryName = string( &buf.front(), len );
|
||||||
|
}
|
||||||
|
|
||||||
// then read the dictionary's encoding
|
// then read the dictionary's encoding
|
||||||
len = idx.read< uint32_t >();
|
len = idx.read< uint32_t >();
|
||||||
buf.resize( len );
|
if( len > 0 )
|
||||||
idx.read( &buf.front(), len );
|
{
|
||||||
encoding = string( &buf.front(), len );
|
buf.resize( len );
|
||||||
|
idx.read( &buf.front(), len );
|
||||||
|
encoding = string( &buf.front(), len );
|
||||||
|
}
|
||||||
|
|
||||||
dictFile.setFileName( QString::fromUtf8( dictionaryFiles[ 0 ].c_str() ) );
|
dictFile.setFileName( QString::fromUtf8( dictionaryFiles[ 0 ].c_str() ) );
|
||||||
dictFile.open( QIODevice::ReadOnly );
|
dictFile.open( QIODevice::ReadOnly );
|
||||||
|
|
7
sdict.cc
7
sdict.cc
|
@ -212,8 +212,11 @@ SdictDictionary::SdictDictionary( string const & id,
|
||||||
|
|
||||||
idx.seek( sizeof( idxHeader ) );
|
idx.seek( sizeof( idxHeader ) );
|
||||||
vector< char > dName( idx.read< uint32_t >() );
|
vector< char > dName( idx.read< uint32_t >() );
|
||||||
idx.read( &dName.front(), dName.size() );
|
if( dName.size() > 0 )
|
||||||
dictionaryName = string( &dName.front(), dName.size() );
|
{
|
||||||
|
idx.read( &dName.front(), dName.size() );
|
||||||
|
dictionaryName = string( &dName.front(), dName.size() );
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize the index
|
// Initialize the index
|
||||||
|
|
||||||
|
|
|
@ -312,6 +312,9 @@ void StardictDictionary::loadIcon() throw()
|
||||||
|
|
||||||
string StardictDictionary::loadString( size_t size )
|
string StardictDictionary::loadString( size_t size )
|
||||||
{
|
{
|
||||||
|
if( size == 0 )
|
||||||
|
return string();
|
||||||
|
|
||||||
vector< char > data( size );
|
vector< char > data( size );
|
||||||
|
|
||||||
idx.read( &data.front(), data.size() );
|
idx.read( &data.front(), data.size() );
|
||||||
|
|
3
utf8.cc
3
utf8.cc
|
@ -133,6 +133,9 @@ long decode( char const * in_, size_t inSize, wchar * out_ )
|
||||||
|
|
||||||
string encode( wstring const & in ) throw()
|
string encode( wstring const & in ) throw()
|
||||||
{
|
{
|
||||||
|
if( in.size() == 0 )
|
||||||
|
return string();
|
||||||
|
|
||||||
std::vector< char > buffer( in.size() * 4 );
|
std::vector< char > buffer( in.size() * 4 );
|
||||||
|
|
||||||
return string( &buffer.front(),
|
return string( &buffer.front(),
|
||||||
|
|
Loading…
Reference in a new issue