From 3c5b76f77a42cbefc4cdf39a4ceda3b4d0839fcf Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Thu, 21 Nov 2024 23:53:10 -0500 Subject: [PATCH] fix startdict index file reading caused by wrong order of reading partially revert https://github.com/xiaoyifang/goldendict-ng/pull/1972 --- src/dict/stardict.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/dict/stardict.cc b/src/dict/stardict.cc index b6bf2749..b03626e8 100644 --- a/src/dict/stardict.cc +++ b/src/dict/stardict.cc @@ -122,7 +122,7 @@ class StardictDictionary: public BtreeIndexing::BtreeDictionary File::Index idx; IdxHeader idxHeader; string sameTypeSequence; - ChunkedStorage::Reader chunks; + std::unique_ptr< ChunkedStorage::Reader > chunks; QMutex dzMutex; dictData * dz; QMutex resourceZipMutex; @@ -215,12 +215,14 @@ StardictDictionary::StardictDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ): BtreeDictionary( id, dictionaryFiles ), - idx( indexFile, QIODevice::ReadOnly ), - idxHeader( idx.read< IdxHeader >() ), - sameTypeSequence( loadString( idxHeader.sameTypeSequenceSize ) ), - chunks( idx, idxHeader.chunksOffset ) + idx( indexFile, QIODevice::ReadOnly ) { - dictionaryName = loadString( idxHeader.bookNameSize ); + // reading headers, note that reading order matters + idxHeader = idx.read< IdxHeader >(); + dictionaryName = loadString( idxHeader.bookNameSize ); + sameTypeSequence = loadString( idxHeader.sameTypeSequenceSize ); + chunks = std::make_unique< ChunkedStorage::Reader >( idx, idxHeader.chunksOffset ); + // Open the .dict file DZ_ERRORS error; @@ -301,7 +303,7 @@ void StardictDictionary::getArticleProps( uint32_t articleAddress, QMutexLocker _( &idxMutex ); - char * articleData = chunks.getBlock( articleAddress, chunk ); + char * articleData = chunks->getBlock( articleAddress, chunk ); memcpy( &offset, articleData, sizeof( uint32_t ) ); articleData += sizeof( uint32_t );