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 f9d1910..90c84f4 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 fa7fb83..039b428 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 a3ea791..86a2297 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 680fc53..60cc824 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;
 }