]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
Fix _memconfig() functions.
authorLasse Collin <lasse.collin@tukaani.org>
Thu, 31 Dec 2009 22:29:10 +0000 (00:29 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Thu, 31 Dec 2009 22:29:10 +0000 (00:29 +0200)
This affects lzma_memusage() and lzma_memlimit_get().

src/liblzma/api/lzma/index.h
src/liblzma/common/alone_decoder.c
src/liblzma/common/index_decoder.c
src/liblzma/common/stream_decoder.c

index f9d1910aaeb2c8b2ddfacb69c7b6d60b187f84bc..90c84f42fe5a72c64de3e6c2d2d29e17317f1ab1 100644 (file)
@@ -615,13 +615,6 @@ extern LZMA_API(lzma_ret) lzma_index_encoder(
  *              - LZMA_MEM_ERROR
  *              - LZMA_MEMLIMIT_ERROR
  *              - LZMA_PROG_ERROR
- *
- * \note        The memory usage limit is checked early in the decoding
- *              (within the first dozen input bytes or so). The actual memory
- *              is allocated later in smaller pieces. If the memory usage
- *              limit is modified with lzma_memlimit_set() after a part
- *              of the Index has already been decoded, the new limit may
- *              get ignored.
  */
 extern LZMA_API(lzma_ret) lzma_index_decoder(
                lzma_stream *strm, lzma_index **i, uint64_t memlimit)
index fa7fb8399cf3eb9b5e26452aaec65317d97c7c1c..039b42859546c7fbe69079a2b8de06d52a705e05 100644 (file)
@@ -173,12 +173,15 @@ static lzma_ret
 alone_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
                uint64_t *old_memlimit, uint64_t new_memlimit)
 {
-       if (new_memlimit != 0 && new_memlimit < coder->memusage)
-               return LZMA_MEMLIMIT_ERROR;
-
        *memusage = coder->memusage;
        *old_memlimit = coder->memlimit;
-       coder->memlimit = new_memlimit;
+
+       if (new_memlimit != 0) {
+               if (new_memlimit < coder->memusage)
+                       return LZMA_MEMLIMIT_ERROR;
+
+               coder->memlimit = new_memlimit;
+       }
 
        return LZMA_OK;
 }
index a3ea791fe19efd516ddc9afee2df0a7fc65d16b2..86a22971b06430990602d9da7183cb38b62d9ac2 100644 (file)
@@ -219,12 +219,14 @@ index_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
                uint64_t *old_memlimit, uint64_t new_memlimit)
 {
        *memusage = lzma_index_memusage(1, coder->count);
+       *old_memlimit = coder->memlimit;
 
-       if (new_memlimit != 0 && new_memlimit < *memusage)
-               return LZMA_MEMLIMIT_ERROR;
+       if (new_memlimit != 0) {
+               if (new_memlimit < *memusage)
+                       return LZMA_MEMLIMIT_ERROR;
 
-       *old_memlimit = coder->memlimit;
-       coder->memlimit = new_memlimit;
+               coder->memlimit = new_memlimit;
+       }
 
        return LZMA_OK;
 }
index 680fc53e252c672f420fae47c3d168ef52ca9db2..60cc82477099b68c32306536c56f2fa4fe03533e 100644 (file)
@@ -383,12 +383,15 @@ static lzma_ret
 stream_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
                uint64_t *old_memlimit, uint64_t new_memlimit)
 {
-       if (new_memlimit != 0 && new_memlimit < coder->memusage)
-               return LZMA_MEMLIMIT_ERROR;
-
        *memusage = coder->memusage;
        *old_memlimit = coder->memlimit;
-       coder->memlimit = new_memlimit;
+
+       if (new_memlimit != 0) {
+               if (new_memlimit < coder->memusage)
+                       return LZMA_MEMLIMIT_ERROR;
+
+               coder->memlimit = new_memlimit;
+       }
 
        return LZMA_OK;
 }