From b4ab3a77c48ed78e6e94de8bcaf8542eff6129c1 Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Fri, 27 Dec 2024 11:50:13 +0800 Subject: [PATCH] opt: add debug log and more friendly error message (#2039) --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- src/dict/utils/indexedzip.cc | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/dict/utils/indexedzip.cc b/src/dict/utils/indexedzip.cc index c1aa4c60e..c4a88597c 100644 --- a/src/dict/utils/indexedzip.cc +++ b/src/dict/utils/indexedzip.cc @@ -84,7 +84,7 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data ) return (size_t)zip.read( &data.front(), data.size() ) == data.size(); case ZipFile::Deflated: { - // Now do the deflation + // Decompress the data using the zlib library QByteArray compressedData = zip.read( header.compressedSize ); @@ -94,9 +94,7 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data ) data.resize( header.uncompressedSize ); - z_stream stream; - - memset( &stream, 0, sizeof( stream ) ); + z_stream stream = {}; stream.next_in = (Bytef *)compressedData.data(); stream.avail_in = compressedData.size(); @@ -108,17 +106,29 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data ) return false; } - if ( inflate( &stream, Z_FINISH ) != Z_STREAM_END ) { - qDebug( "Not zstream end!" ); + int ret = inflate( &stream, Z_FINISH ); + if ( ret != Z_STREAM_END ) { + qDebug() << "Not zstream end! Stream total_in:" << stream.total_in << "total_out:" << stream.total_out + << "msg:" << ( stream.msg ? stream.msg : "none" ); data.clear(); - inflateEnd( &stream ); + int endRet = inflateEnd( &stream ); + if ( endRet != Z_OK ) { + qDebug() << "inflateEnd failed after inflate! msg:" << ( stream.msg ? stream.msg : "none" ); + } return false; } - inflateEnd( &stream ); + ret = inflateEnd( &stream ); + if ( ret != Z_OK ) { + qDebug() << "inflateEnd failed! msg:" << ( stream.msg ? stream.msg : "none" ); + + data.clear(); + + return false; + } return true; }