From 7dd21df678aafaba8614ffe90188712f13b3bfc3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 13 Feb 2018 07:58:53 +0100 Subject: Merging upstream version 1.10. Signed-off-by: Daniel Baumann --- decoder.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'decoder.h') diff --git a/decoder.h b/decoder.h index e3a4f1c..7ec3133 100644 --- a/decoder.h +++ b/decoder.h @@ -1,5 +1,5 @@ /* Lunzip - Decompressor for the lzip format - Copyright (C) 2010-2017 Antonio Diaz Diaz. + Copyright (C) 2010-2018 Antonio Diaz Diaz. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -244,11 +244,7 @@ unsigned seek_read_back( const int fd, uint8_t * const buf, const int size, const int offset ); static inline uint8_t LZd_peek_prev( const struct LZ_decoder * const d ) - { - if( d->pos > 0 ) return d->buffer[d->pos-1]; - if( d->pos_wrapped ) return d->buffer[d->buffer_size-1]; - return 0; /* prev_byte of first byte */ - } + { return d->buffer[((d->pos > 0) ? d->pos : d->buffer_size)-1]; } static inline uint8_t LZd_peek( const struct LZ_decoder * const d, const unsigned distance ) @@ -338,6 +334,8 @@ static inline bool LZd_init( struct LZ_decoder * const d, d->outfd = ofd; d->pos_wrapped = false; d->pos_wrapped_dic = false; + /* prev_byte of first byte; also for LZd_peek( 0 ) on corrupt file */ + d->buffer[d->buffer_size-1] = 0; return true; } -- cgit v1.2.3