2007-12-09 00:42:33 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-06-03 20:41:54 +03:00
|
|
|
/// \file common.c
|
2008-08-28 22:53:15 +03:00
|
|
|
/// \brief Common functions needed in many places in liblzma
|
2007-12-09 00:42:33 +02:00
|
|
|
//
|
2009-04-13 11:27:40 +03:00
|
|
|
// Author: Lasse Collin
|
2007-12-09 00:42:33 +02:00
|
|
|
//
|
2009-04-13 11:27:40 +03:00
|
|
|
// This file has been put into the public domain.
|
|
|
|
// You can do whatever you want with this file.
|
2007-12-09 00:42:33 +02:00
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
|
2008-08-28 22:53:15 +03:00
|
|
|
/////////////
|
|
|
|
// Version //
|
|
|
|
/////////////
|
|
|
|
|
2009-02-02 20:14:03 +02:00
|
|
|
extern LZMA_API(uint32_t)
|
2008-08-28 22:53:15 +03:00
|
|
|
lzma_version_number(void)
|
|
|
|
{
|
|
|
|
return LZMA_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-02 20:14:03 +02:00
|
|
|
extern LZMA_API(const char *)
|
2008-08-28 22:53:15 +03:00
|
|
|
lzma_version_string(void)
|
|
|
|
{
|
2009-02-13 18:00:03 +02:00
|
|
|
return LZMA_VERSION_STRING;
|
2008-08-28 22:53:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////
|
|
|
|
// Memory allocation //
|
|
|
|
///////////////////////
|
|
|
|
|
2011-05-17 11:54:38 +03:00
|
|
|
extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
|
2012-07-17 18:19:59 +03:00
|
|
|
lzma_alloc(size_t size, const lzma_allocator *allocator)
|
2008-08-28 22:53:15 +03:00
|
|
|
{
|
|
|
|
// Some malloc() variants return NULL if called with size == 0.
|
|
|
|
if (size == 0)
|
|
|
|
size = 1;
|
|
|
|
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
if (allocator != NULL && allocator->alloc != NULL)
|
|
|
|
ptr = allocator->alloc(allocator->opaque, 1, size);
|
|
|
|
else
|
|
|
|
ptr = malloc(size);
|
|
|
|
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-25 19:25:57 +03:00
|
|
|
extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
|
|
|
|
lzma_alloc_zero(size_t size, const lzma_allocator *allocator)
|
|
|
|
{
|
|
|
|
// Some calloc() variants return NULL if called with size == 0.
|
|
|
|
if (size == 0)
|
|
|
|
size = 1;
|
|
|
|
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
if (allocator != NULL && allocator->alloc != NULL) {
|
|
|
|
ptr = allocator->alloc(allocator->opaque, 1, size);
|
|
|
|
if (ptr != NULL)
|
|
|
|
memzero(ptr, size);
|
|
|
|
} else {
|
|
|
|
ptr = calloc(1, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-28 22:53:15 +03:00
|
|
|
extern void
|
2012-07-17 18:19:59 +03:00
|
|
|
lzma_free(void *ptr, const lzma_allocator *allocator)
|
2008-08-28 22:53:15 +03:00
|
|
|
{
|
|
|
|
if (allocator != NULL && allocator->free != NULL)
|
|
|
|
allocator->free(allocator->opaque, ptr);
|
|
|
|
else
|
|
|
|
free(ptr);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////
|
|
|
|
// Misc //
|
|
|
|
//////////
|
|
|
|
|
|
|
|
extern size_t
|
|
|
|
lzma_bufcpy(const uint8_t *restrict in, size_t *restrict in_pos,
|
|
|
|
size_t in_size, uint8_t *restrict out,
|
|
|
|
size_t *restrict out_pos, size_t out_size)
|
|
|
|
{
|
|
|
|
const size_t in_avail = in_size - *in_pos;
|
|
|
|
const size_t out_avail = out_size - *out_pos;
|
2010-05-26 10:36:46 +03:00
|
|
|
const size_t copy_size = my_min(in_avail, out_avail);
|
2008-08-28 22:53:15 +03:00
|
|
|
|
liblzma: Avoid memcpy(NULL, foo, 0) because it is undefined behavior.
I should have always known this but I didn't. Here is an example
as a reminder to myself:
int mycopy(void *dest, void *src, size_t n)
{
memcpy(dest, src, n);
return dest == NULL;
}
In the example, a compiler may assume that dest != NULL because
passing NULL to memcpy() would be undefined behavior. Testing
with GCC 8.2.1, mycopy(NULL, NULL, 0) returns 1 with -O0 and -O1.
With -O2 the return value is 0 because the compiler infers that
dest cannot be NULL because it was already used with memcpy()
and thus the test for NULL gets optimized out.
In liblzma, if a null-pointer was passed to memcpy(), there were
no checks for NULL *after* the memcpy() call, so I cautiously
suspect that it shouldn't have caused bad behavior in practice,
but it's hard to be sure, and the problematic cases had to be
fixed anyway.
Thanks to Jeffrey Walton.
2019-05-13 20:05:17 +03:00
|
|
|
// Call memcpy() only if there is something to copy. If there is
|
|
|
|
// nothing to copy, in or out might be NULL and then the memcpy()
|
|
|
|
// call would trigger undefined behavior.
|
|
|
|
if (copy_size > 0)
|
|
|
|
memcpy(out + *out_pos, in + *in_pos, copy_size);
|
2008-08-28 22:53:15 +03:00
|
|
|
|
|
|
|
*in_pos += copy_size;
|
|
|
|
*out_pos += copy_size;
|
|
|
|
|
|
|
|
return copy_size;
|
|
|
|
}
|
2007-12-09 00:42:33 +02:00
|
|
|
|
|
|
|
|
2008-08-28 22:53:15 +03:00
|
|
|
extern lzma_ret
|
2012-07-17 18:19:59 +03:00
|
|
|
lzma_next_filter_init(lzma_next_coder *next, const lzma_allocator *allocator,
|
2008-08-28 22:53:15 +03:00
|
|
|
const lzma_filter_info *filters)
|
|
|
|
{
|
|
|
|
lzma_next_coder_init(filters[0].init, next, allocator);
|
2009-11-14 18:59:19 +02:00
|
|
|
next->id = filters[0].id;
|
2008-08-28 22:53:15 +03:00
|
|
|
return filters[0].init == NULL
|
|
|
|
? LZMA_OK : filters[0].init(next, allocator, filters);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-14 18:59:19 +02:00
|
|
|
extern lzma_ret
|
2012-07-17 18:19:59 +03:00
|
|
|
lzma_next_filter_update(lzma_next_coder *next, const lzma_allocator *allocator,
|
2009-11-14 18:59:19 +02:00
|
|
|
const lzma_filter *reversed_filters)
|
|
|
|
{
|
|
|
|
// Check that the application isn't trying to change the Filter ID.
|
|
|
|
// End of filters is indicated with LZMA_VLI_UNKNOWN in both
|
|
|
|
// reversed_filters[0].id and next->id.
|
|
|
|
if (reversed_filters[0].id != next->id)
|
|
|
|
return LZMA_PROG_ERROR;
|
|
|
|
|
|
|
|
if (reversed_filters[0].id == LZMA_VLI_UNKNOWN)
|
|
|
|
return LZMA_OK;
|
|
|
|
|
|
|
|
assert(next->update != NULL);
|
|
|
|
return next->update(next->coder, allocator, NULL, reversed_filters);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-28 22:53:15 +03:00
|
|
|
extern void
|
2012-07-17 18:19:59 +03:00
|
|
|
lzma_next_end(lzma_next_coder *next, const lzma_allocator *allocator)
|
2008-08-28 22:53:15 +03:00
|
|
|
{
|
|
|
|
if (next->init != (uintptr_t)(NULL)) {
|
|
|
|
// To avoid tiny end functions that simply call
|
|
|
|
// lzma_free(coder, allocator), we allow leaving next->end
|
|
|
|
// NULL and call lzma_free() here.
|
|
|
|
if (next->end != NULL)
|
|
|
|
next->end(next->coder, allocator);
|
|
|
|
else
|
|
|
|
lzma_free(next->coder, allocator);
|
|
|
|
|
|
|
|
// Reset the variables so the we don't accidentally think
|
|
|
|
// that it is an already initialized coder.
|
|
|
|
*next = LZMA_NEXT_CODER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////
|
|
|
|
// External to internal API wrapper //
|
|
|
|
//////////////////////////////////////
|
|
|
|
|
2007-12-09 00:42:33 +02:00
|
|
|
extern lzma_ret
|
|
|
|
lzma_strm_init(lzma_stream *strm)
|
|
|
|
{
|
|
|
|
if (strm == NULL)
|
|
|
|
return LZMA_PROG_ERROR;
|
|
|
|
|
|
|
|
if (strm->internal == NULL) {
|
|
|
|
strm->internal = lzma_alloc(sizeof(lzma_internal),
|
|
|
|
strm->allocator);
|
|
|
|
if (strm->internal == NULL)
|
|
|
|
return LZMA_MEM_ERROR;
|
|
|
|
|
|
|
|
strm->internal->next = LZMA_NEXT_CODER_INIT;
|
|
|
|
}
|
|
|
|
|
2011-04-11 19:28:18 +03:00
|
|
|
memzero(strm->internal->supported_actions,
|
|
|
|
sizeof(strm->internal->supported_actions));
|
2007-12-09 00:42:33 +02:00
|
|
|
strm->internal->sequence = ISEQ_RUN;
|
2010-03-06 21:17:20 +02:00
|
|
|
strm->internal->allow_buf_error = false;
|
2007-12-09 00:42:33 +02:00
|
|
|
|
|
|
|
strm->total_in = 0;
|
|
|
|
strm->total_out = 0;
|
|
|
|
|
|
|
|
return LZMA_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-02 20:14:03 +02:00
|
|
|
extern LZMA_API(lzma_ret)
|
2007-12-09 00:42:33 +02:00
|
|
|
lzma_code(lzma_stream *strm, lzma_action action)
|
|
|
|
{
|
|
|
|
// Sanity checks
|
|
|
|
if ((strm->next_in == NULL && strm->avail_in != 0)
|
|
|
|
|| (strm->next_out == NULL && strm->avail_out != 0)
|
|
|
|
|| strm->internal == NULL
|
|
|
|
|| strm->internal->next.code == NULL
|
2013-10-02 12:55:11 +03:00
|
|
|
|| (unsigned int)(action) > LZMA_ACTION_MAX
|
2007-12-09 00:42:33 +02:00
|
|
|
|| !strm->internal->supported_actions[action])
|
|
|
|
return LZMA_PROG_ERROR;
|
|
|
|
|
2010-10-23 12:30:54 +03:00
|
|
|
// Check if unsupported members have been set to non-zero or non-NULL,
|
|
|
|
// which would indicate that some new feature is wanted.
|
|
|
|
if (strm->reserved_ptr1 != NULL
|
|
|
|
|| strm->reserved_ptr2 != NULL
|
|
|
|
|| strm->reserved_ptr3 != NULL
|
|
|
|
|| strm->reserved_ptr4 != NULL
|
|
|
|
|| strm->reserved_int2 != 0
|
|
|
|
|| strm->reserved_int3 != 0
|
|
|
|
|| strm->reserved_int4 != 0
|
|
|
|
|| strm->reserved_enum1 != LZMA_RESERVED_ENUM
|
|
|
|
|| strm->reserved_enum2 != LZMA_RESERVED_ENUM)
|
|
|
|
return LZMA_OPTIONS_ERROR;
|
|
|
|
|
2007-12-09 00:42:33 +02:00
|
|
|
switch (strm->internal->sequence) {
|
|
|
|
case ISEQ_RUN:
|
|
|
|
switch (action) {
|
|
|
|
case LZMA_RUN:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LZMA_SYNC_FLUSH:
|
|
|
|
strm->internal->sequence = ISEQ_SYNC_FLUSH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LZMA_FULL_FLUSH:
|
|
|
|
strm->internal->sequence = ISEQ_FULL_FLUSH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LZMA_FINISH:
|
|
|
|
strm->internal->sequence = ISEQ_FINISH;
|
|
|
|
break;
|
2013-10-02 12:55:11 +03:00
|
|
|
|
|
|
|
case LZMA_FULL_BARRIER:
|
|
|
|
strm->internal->sequence = ISEQ_FULL_BARRIER;
|
|
|
|
break;
|
2007-12-09 00:42:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ISEQ_SYNC_FLUSH:
|
2009-01-20 10:35:15 +02:00
|
|
|
// The same action must be used until we return
|
|
|
|
// LZMA_STREAM_END, and the amount of input must not change.
|
|
|
|
if (action != LZMA_SYNC_FLUSH
|
|
|
|
|| strm->internal->avail_in != strm->avail_in)
|
2007-12-09 00:42:33 +02:00
|
|
|
return LZMA_PROG_ERROR;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ISEQ_FULL_FLUSH:
|
2009-01-20 10:35:15 +02:00
|
|
|
if (action != LZMA_FULL_FLUSH
|
|
|
|
|| strm->internal->avail_in != strm->avail_in)
|
2007-12-09 00:42:33 +02:00
|
|
|
return LZMA_PROG_ERROR;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ISEQ_FINISH:
|
2009-01-20 10:35:15 +02:00
|
|
|
if (action != LZMA_FINISH
|
|
|
|
|| strm->internal->avail_in != strm->avail_in)
|
2007-12-09 00:42:33 +02:00
|
|
|
return LZMA_PROG_ERROR;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2013-10-02 12:55:11 +03:00
|
|
|
case ISEQ_FULL_BARRIER:
|
|
|
|
if (action != LZMA_FULL_BARRIER
|
|
|
|
|| strm->internal->avail_in != strm->avail_in)
|
|
|
|
return LZMA_PROG_ERROR;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2007-12-09 00:42:33 +02:00
|
|
|
case ISEQ_END:
|
|
|
|
return LZMA_STREAM_END;
|
|
|
|
|
|
|
|
case ISEQ_ERROR:
|
|
|
|
default:
|
|
|
|
return LZMA_PROG_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t in_pos = 0;
|
|
|
|
size_t out_pos = 0;
|
|
|
|
lzma_ret ret = strm->internal->next.code(
|
|
|
|
strm->internal->next.coder, strm->allocator,
|
|
|
|
strm->next_in, &in_pos, strm->avail_in,
|
|
|
|
strm->next_out, &out_pos, strm->avail_out, action);
|
|
|
|
|
|
|
|
strm->next_in += in_pos;
|
|
|
|
strm->avail_in -= in_pos;
|
|
|
|
strm->total_in += in_pos;
|
|
|
|
|
|
|
|
strm->next_out += out_pos;
|
|
|
|
strm->avail_out -= out_pos;
|
|
|
|
strm->total_out += out_pos;
|
|
|
|
|
|
|
|
strm->internal->avail_in = strm->avail_in;
|
|
|
|
|
2019-06-24 23:25:41 +03:00
|
|
|
switch (ret) {
|
2007-12-09 00:42:33 +02:00
|
|
|
case LZMA_OK:
|
|
|
|
// Don't return LZMA_BUF_ERROR when it happens the first time.
|
|
|
|
// This is to avoid returning LZMA_BUF_ERROR when avail_out
|
|
|
|
// was zero but still there was no more data left to written
|
|
|
|
// to next_out.
|
|
|
|
if (out_pos == 0 && in_pos == 0) {
|
|
|
|
if (strm->internal->allow_buf_error)
|
|
|
|
ret = LZMA_BUF_ERROR;
|
|
|
|
else
|
|
|
|
strm->internal->allow_buf_error = true;
|
|
|
|
} else {
|
|
|
|
strm->internal->allow_buf_error = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-04-11 22:03:30 +03:00
|
|
|
case LZMA_TIMED_OUT:
|
|
|
|
strm->internal->allow_buf_error = false;
|
|
|
|
ret = LZMA_OK;
|
|
|
|
break;
|
|
|
|
|
2017-04-21 15:05:16 +03:00
|
|
|
case LZMA_SEEK_NEEDED:
|
2017-03-30 20:00:09 +03:00
|
|
|
strm->internal->allow_buf_error = false;
|
|
|
|
|
|
|
|
// If LZMA_FINISH was used, reset it back to the
|
|
|
|
// LZMA_RUN-based state so that new input can be supplied
|
|
|
|
// by the application.
|
|
|
|
if (strm->internal->sequence == ISEQ_FINISH)
|
|
|
|
strm->internal->sequence = ISEQ_RUN;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2007-12-09 00:42:33 +02:00
|
|
|
case LZMA_STREAM_END:
|
|
|
|
if (strm->internal->sequence == ISEQ_SYNC_FLUSH
|
2013-10-02 12:55:11 +03:00
|
|
|
|| strm->internal->sequence == ISEQ_FULL_FLUSH
|
|
|
|
|| strm->internal->sequence
|
|
|
|
== ISEQ_FULL_BARRIER)
|
2007-12-09 00:42:33 +02:00
|
|
|
strm->internal->sequence = ISEQ_RUN;
|
|
|
|
else
|
|
|
|
strm->internal->sequence = ISEQ_END;
|
|
|
|
|
2009-01-19 22:53:18 +02:00
|
|
|
// Fall through
|
|
|
|
|
|
|
|
case LZMA_NO_CHECK:
|
2007-12-09 00:42:33 +02:00
|
|
|
case LZMA_UNSUPPORTED_CHECK:
|
2009-01-19 22:53:18 +02:00
|
|
|
case LZMA_GET_CHECK:
|
|
|
|
case LZMA_MEMLIMIT_ERROR:
|
|
|
|
// Something else than LZMA_OK, but not a fatal error,
|
|
|
|
// that is, coding may be continued (except if ISEQ_END).
|
2007-12-09 00:42:33 +02:00
|
|
|
strm->internal->allow_buf_error = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// All the other errors are fatal; coding cannot be continued.
|
2009-01-19 22:53:18 +02:00
|
|
|
assert(ret != LZMA_BUF_ERROR);
|
2007-12-09 00:42:33 +02:00
|
|
|
strm->internal->sequence = ISEQ_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-02 20:14:03 +02:00
|
|
|
extern LZMA_API(void)
|
2007-12-09 00:42:33 +02:00
|
|
|
lzma_end(lzma_stream *strm)
|
|
|
|
{
|
|
|
|
if (strm != NULL && strm->internal != NULL) {
|
2008-08-28 22:53:15 +03:00
|
|
|
lzma_next_end(&strm->internal->next, strm->allocator);
|
2007-12-09 00:42:33 +02:00
|
|
|
lzma_free(strm->internal, strm->allocator);
|
|
|
|
strm->internal = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2008-09-06 15:14:30 +03:00
|
|
|
|
|
|
|
|
2012-12-14 20:13:32 +02:00
|
|
|
extern LZMA_API(void)
|
|
|
|
lzma_get_progress(lzma_stream *strm,
|
|
|
|
uint64_t *progress_in, uint64_t *progress_out)
|
|
|
|
{
|
|
|
|
if (strm->internal->next.get_progress != NULL) {
|
|
|
|
strm->internal->next.get_progress(strm->internal->next.coder,
|
|
|
|
progress_in, progress_out);
|
|
|
|
} else {
|
|
|
|
*progress_in = strm->total_in;
|
|
|
|
*progress_out = strm->total_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-02 20:14:03 +02:00
|
|
|
extern LZMA_API(lzma_check)
|
2008-09-06 15:14:30 +03:00
|
|
|
lzma_get_check(const lzma_stream *strm)
|
|
|
|
{
|
2008-12-15 19:39:13 +02:00
|
|
|
// Return LZMA_CHECK_NONE if we cannot know the check type.
|
|
|
|
// It's a bug in the application if this happens.
|
|
|
|
if (strm->internal->next.get_check == NULL)
|
|
|
|
return LZMA_CHECK_NONE;
|
|
|
|
|
2008-09-06 15:14:30 +03:00
|
|
|
return strm->internal->next.get_check(strm->internal->next.coder);
|
|
|
|
}
|
2008-12-15 19:39:13 +02:00
|
|
|
|
|
|
|
|
2009-02-02 20:14:03 +02:00
|
|
|
extern LZMA_API(uint64_t)
|
2008-12-15 19:39:13 +02:00
|
|
|
lzma_memusage(const lzma_stream *strm)
|
|
|
|
{
|
|
|
|
uint64_t memusage;
|
|
|
|
uint64_t old_memlimit;
|
|
|
|
|
|
|
|
if (strm == NULL || strm->internal == NULL
|
|
|
|
|| strm->internal->next.memconfig == NULL
|
|
|
|
|| strm->internal->next.memconfig(
|
|
|
|
strm->internal->next.coder,
|
|
|
|
&memusage, &old_memlimit, 0) != LZMA_OK)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return memusage;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-02 20:14:03 +02:00
|
|
|
extern LZMA_API(uint64_t)
|
2008-12-15 19:39:13 +02:00
|
|
|
lzma_memlimit_get(const lzma_stream *strm)
|
|
|
|
{
|
|
|
|
uint64_t old_memlimit;
|
|
|
|
uint64_t memusage;
|
|
|
|
|
|
|
|
if (strm == NULL || strm->internal == NULL
|
|
|
|
|| strm->internal->next.memconfig == NULL
|
|
|
|
|| strm->internal->next.memconfig(
|
|
|
|
strm->internal->next.coder,
|
|
|
|
&memusage, &old_memlimit, 0) != LZMA_OK)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return old_memlimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-02 20:14:03 +02:00
|
|
|
extern LZMA_API(lzma_ret)
|
2008-12-15 19:39:13 +02:00
|
|
|
lzma_memlimit_set(lzma_stream *strm, uint64_t new_memlimit)
|
|
|
|
{
|
|
|
|
// Dummy variables to simplify memconfig functions
|
|
|
|
uint64_t old_memlimit;
|
|
|
|
uint64_t memusage;
|
|
|
|
|
|
|
|
if (strm == NULL || strm->internal == NULL
|
|
|
|
|| strm->internal->next.memconfig == NULL)
|
|
|
|
return LZMA_PROG_ERROR;
|
|
|
|
|
2017-03-30 19:47:45 +03:00
|
|
|
// Zero is a special value that cannot be used as an actual limit.
|
|
|
|
// If 0 was specified, use 1 instead.
|
|
|
|
if (new_memlimit == 0)
|
|
|
|
new_memlimit = 1;
|
2008-12-15 19:39:13 +02:00
|
|
|
|
|
|
|
return strm->internal->next.memconfig(strm->internal->next.coder,
|
|
|
|
&memusage, &old_memlimit, new_memlimit);
|
|
|
|
}
|