summaryrefslogtreecommitdiffstats
path: root/decoder.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-10-22 16:37:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-10-22 16:37:22 +0000
commit939046a7771762bfb5469449e29bfb8cdc453e03 (patch)
tree1d7bd66ed9cb663e244a4537a21f159dee3296c8 /decoder.h
parentAdding upstream version 1.15~pre1. (diff)
downloadlzlib-upstream.tar.xz
lzlib-upstream.zip
Adding upstream version 1.15~pre2.upstream/1.15_pre2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--decoder.h14
1 files changed, 8 insertions, 6 deletions
diff --git a/decoder.h b/decoder.h
index 4b91fec..57e47cb 100644
--- a/decoder.h
+++ b/decoder.h
@@ -133,13 +133,15 @@ static inline bool Rd_unread_data( struct Range_decoder * const rdec,
return true;
}
-static bool Rd_try_reload( struct Range_decoder * const rdec )
+static int Rd_try_reload( struct Range_decoder * const rdec )
{
if( rdec->reload_pending && Rd_available_bytes( rdec ) >= 5 )
{
rdec->reload_pending = false;
rdec->code = 0;
rdec->range = 0xFFFFFFFFU;
+ /* check first byte of the LZMA stream without reading it */
+ if( rdec->cb.buffer[rdec->cb.get] != 0 ) return 2;
Rd_get_byte( rdec ); /* discard first byte of the LZMA stream */
int i; for( i = 0; i < 4; ++i )
rdec->code = (rdec->code << 8) | Rd_get_byte( rdec );
@@ -164,7 +166,7 @@ static inline unsigned Rd_decode( struct Range_decoder * const rdec,
rdec->range >>= 1;
/* symbol <<= 1; */
/* if( rdec->code >= rdec->range ) { rdec->code -= rdec->range; symbol |= 1; } */
- const bool bit = ( rdec->code >= rdec->range );
+ const bool bit = rdec->code >= rdec->range;
symbol <<= 1; symbol += bit;
rdec->code -= rdec->range & ( 0U - bit );
}
@@ -387,14 +389,14 @@ static inline void LZd_copy_block( struct LZ_decoder * const d,
bool fast, fast2;
if( lpos > distance )
{
- fast = ( len < d->cb.buffer_size - lpos );
- fast2 = ( fast && len <= lpos - i );
+ fast = len < d->cb.buffer_size - lpos;
+ fast2 = fast && len <= lpos - i;
}
else
{
i += d->cb.buffer_size;
- fast = ( len < d->cb.buffer_size - i ); /* (i == pos) may happen */
- fast2 = ( fast && len <= i - lpos );
+ fast = len < d->cb.buffer_size - i; /* (i == pos) may happen */
+ fast2 = fast && len <= i - lpos;
}
if( fast ) /* no wrap */
{