summaryrefslogtreecommitdiffstats
path: root/decoder.h
diff options
context:
space:
mode:
Diffstat (limited to 'decoder.h')
-rw-r--r--decoder.h10
1 files changed, 4 insertions, 6 deletions
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;
}