aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/common/vli_decoder.c
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2008-11-23 15:09:03 +0200
committerLasse Collin <lasse.collin@tukaani.org>2008-11-23 15:09:03 +0200
commit69472ee5f055a2bb6f28106f0923e1461fd1d080 (patch)
treeda00034ec0ee278ca2537674444140f574cf71af /src/liblzma/common/vli_decoder.c
parentTypo fix (diff)
downloadxz-69472ee5f055a2bb6f28106f0923e1461fd1d080.tar.xz
VLI encoder and decoder cleanups. Made encoder return
LZMA_PROG_ERROR in single-call mode if there's no output space.
Diffstat (limited to 'src/liblzma/common/vli_decoder.c')
-rw-r--r--src/liblzma/common/vli_decoder.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/liblzma/common/vli_decoder.c b/src/liblzma/common/vli_decoder.c
index 60874baa..78ef539a 100644
--- a/src/liblzma/common/vli_decoder.c
+++ b/src/liblzma/common/vli_decoder.c
@@ -53,24 +53,27 @@ lzma_vli_decode(lzma_vli *restrict vli, size_t *restrict vli_pos,
}
do {
- // Read the next byte.
- *vli |= (lzma_vli)(in[*in_pos] & 0x7F) << (*vli_pos * 7);
+ // Read the next byte. Use a temporary variable so that we
+ // can update *in_pos immediatelly.
+ const uint8_t byte = in[*in_pos];
+ ++*in_pos;
+
+ // Add the newly read byte to *vli.
+ *vli += (lzma_vli)(byte & 0x7F) << (*vli_pos * 7);
++*vli_pos;
// Check if this is the last byte of a multibyte integer.
- if (!(in[*in_pos] & 0x80)) {
+ if ((byte & 0x80) == 0) {
// We don't allow using variable-length integers as
// padding i.e. the encoding must use the most the
// compact form.
- if (in[(*in_pos)++] == 0x00 && *vli_pos > 1)
+ if (byte == 0x00 && *vli_pos > 1)
return LZMA_DATA_ERROR;
return vli_pos == &vli_pos_internal
? LZMA_OK : LZMA_STREAM_END;
}
- ++*in_pos;
-
// There is at least one more byte coming. If we have already
// read maximum number of bytes, the integer is considered
// corrupt.