summaryrefslogtreecommitdiffstats
path: root/decoder.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--decoder.h10
1 files changed, 4 insertions, 6 deletions
diff --git a/decoder.h b/decoder.h
index 8e422a8..090bf3a 100644
--- a/decoder.h
+++ b/decoder.h
@@ -1,5 +1,5 @@
/* Lzlib - Compression library for the lzip format
- Copyright (C) 2009-2017 Antonio Diaz Diaz.
+ Copyright (C) 2009-2018 Antonio Diaz Diaz.
This library is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
@@ -319,11 +319,7 @@ static inline bool LZd_enough_free_bytes( const struct LZ_decoder * const d )
{ return Cb_free_bytes( &d->cb ) >= lzd_min_free_bytes; }
static inline uint8_t LZd_peek_prev( const struct LZ_decoder * const d )
- {
- if( d->cb.put > 0 ) return d->cb.buffer[d->cb.put-1];
- if( d->pos_wrapped ) return d->cb.buffer[d->cb.buffer_size-1];
- return 0; /* prev_byte of first byte */
- }
+ { return d->cb.buffer[((d->cb.put > 0) ? d->cb.put : d->cb.buffer_size)-1]; }
static inline uint8_t LZd_peek( const struct LZ_decoder * const d,
const unsigned distance )
@@ -387,6 +383,8 @@ static inline bool LZd_init( struct LZ_decoder * const d,
d->member_finished = false;
d->verify_trailer_pending = false;
d->pos_wrapped = false;
+ /* prev_byte of first byte; also for LZd_peek( 0 ) on corrupt file */
+ d->cb.buffer[d->cb.buffer_size-1] = 0;
d->rep0 = 0;
d->rep1 = 0;
d->rep2 = 0;