fix: code smell ,remove while(1)

This commit is contained in:
Xiao Yi Fang 2024-08-10 17:02:38 +08:00
parent 752b880f24
commit 9842761c1c

View file

@ -14,10 +14,9 @@ QByteArray zlibDecompress( const char * bufptr, unsigned length )
memset( &zs, 0, sizeof( zs ) ); memset( &zs, 0, sizeof( zs ) );
zs.next_in = (Bytef *)bufptr; zs.next_in = (Bytef *)bufptr;
zs.avail_in = length; zs.avail_in = length;
while ( 1 ) {
res = inflateInit( &zs ); res = inflateInit( &zs );
if ( res != Z_OK )
break; if ( res == Z_OK ) {
while ( res != Z_STREAM_END ) { while ( res != Z_STREAM_END ) {
zs.next_out = (Bytef *)buf; zs.next_out = (Bytef *)buf;
zs.avail_out = CHUNK_SIZE; zs.avail_out = CHUNK_SIZE;
@ -26,8 +25,8 @@ QByteArray zlibDecompress( const char * bufptr, unsigned length )
if ( res != Z_OK && res != Z_STREAM_END ) if ( res != Z_OK && res != Z_STREAM_END )
break; break;
} }
break;
} }
inflateEnd( &zs ); inflateEnd( &zs );
if ( res != Z_STREAM_END ) if ( res != Z_STREAM_END )
str.clear(); str.clear();
@ -50,10 +49,8 @@ string decompressBzip2( const char * bufptr, unsigned length )
zs.next_in = (char *)bufptr; zs.next_in = (char *)bufptr;
zs.avail_in = length; zs.avail_in = length;
zs.total_in_lo32 = length; zs.total_in_lo32 = length;
while ( 1 ) {
res = BZ2_bzDecompressInit( &zs, 0, 0 ); res = BZ2_bzDecompressInit( &zs, 0, 0 );
if ( res != BZ_OK ) if ( res == BZ_OK ) {
break;
while ( res != BZ_STREAM_END ) { while ( res != BZ_STREAM_END ) {
zs.next_out = buf; zs.next_out = buf;
zs.avail_out = CHUNK_SIZE; zs.avail_out = CHUNK_SIZE;
@ -63,7 +60,6 @@ string decompressBzip2( const char * bufptr, unsigned length )
if ( res != BZ_OK && res != BZ_STREAM_END ) if ( res != BZ_OK && res != BZ_STREAM_END )
break; break;
} }
break;
} }
BZ2_bzDecompressEnd( &zs ); BZ2_bzDecompressEnd( &zs );
if ( res != BZ_STREAM_END ) if ( res != BZ_STREAM_END )
@ -92,14 +88,13 @@ string decompressLzma2( const char * bufptr, unsigned length, bool raw_decoder )
filters[ 1 ].id = LZMA_VLI_UNKNOWN; filters[ 1 ].id = LZMA_VLI_UNKNOWN;
} }
while ( 1 ) {
if ( raw_decoder ) if ( raw_decoder )
res = lzma_raw_decoder( &strm, filters ); res = lzma_raw_decoder( &strm, filters );
else else
res = lzma_stream_decoder( &strm, UINT64_MAX, 0 ); res = lzma_stream_decoder( &strm, UINT64_MAX, 0 );
if ( res != LZMA_OK ) if ( res == LZMA_OK ) {
break;
while ( res != LZMA_STREAM_END ) { while ( res != LZMA_STREAM_END ) {
strm.next_out = reinterpret_cast< uint8_t * >( buf ); strm.next_out = reinterpret_cast< uint8_t * >( buf );
@ -112,8 +107,7 @@ string decompressLzma2( const char * bufptr, unsigned length, bool raw_decoder )
lzma_end( &strm ); lzma_end( &strm );
if ( res != LZMA_STREAM_END ) if ( res != LZMA_STREAM_END )
str.clear(); str.clear();
break;
} }
return str; return str;
} }