index.c   index.c 
skipping to change at line 184 skipping to change at line 184
{ {
tree->root = NULL; tree->root = NULL;
tree->leftmost = NULL; tree->leftmost = NULL;
tree->rightmost = NULL; tree->rightmost = NULL;
tree->count = 0; tree->count = 0;
return; return;
} }
/// Helper for index_tree_end() /// Helper for index_tree_end()
static void static void
index_tree_node_end(index_tree_node *node, lzma_allocator *allocator, index_tree_node_end(index_tree_node *node, const lzma_allocator *allocator,
void (*free_func)(void *node, lzma_allocator *allocator)) void (*free_func)(void *node, const lzma_allocator *allocato
r))
{ {
// The tree won't ever be very huge, so recursion should be fine. // The tree won't ever be very huge, so recursion should be fine.
// 20 levels in the tree is likely quite a lot already in practice. // 20 levels in the tree is likely quite a lot already in practice.
if (node->left != NULL) if (node->left != NULL)
index_tree_node_end(node->left, allocator, free_func); index_tree_node_end(node->left, allocator, free_func);
if (node->right != NULL) if (node->right != NULL)
index_tree_node_end(node->right, allocator, free_func); index_tree_node_end(node->right, allocator, free_func);
if (free_func != NULL) if (free_func != NULL)
skipping to change at line 207 skipping to change at line 207
lzma_free(node, allocator); lzma_free(node, allocator);
return; return;
} }
/// Free the meory allocated for a tree. If free_func is not NULL, /// Free the meory allocated for a tree. If free_func is not NULL,
/// it is called on each node before freeing the node. This is used /// it is called on each node before freeing the node. This is used
/// to free the Record groups from each index_stream before freeing /// to free the Record groups from each index_stream before freeing
/// the index_stream itself. /// the index_stream itself.
static void static void
index_tree_end(index_tree *tree, lzma_allocator *allocator, index_tree_end(index_tree *tree, const lzma_allocator *allocator,
void (*free_func)(void *node, lzma_allocator *allocator)) void (*free_func)(void *node, const lzma_allocator *allocato
r))
{ {
if (tree->root != NULL) if (tree->root != NULL)
index_tree_node_end(tree->root, allocator, free_func); index_tree_node_end(tree->root, allocator, free_func);
return; return;
} }
/// Add a new node to the tree. node->uncompressed_base and /// Add a new node to the tree. node->uncompressed_base and
/// node->compressed_base must have been set by the caller already. /// node->compressed_base must have been set by the caller already.
static void static void
skipping to change at line 328 skipping to change at line 328
} }
} }
return (void *)(result); return (void *)(result);
} }
/// Allocate and initialize a new Stream using the given base offsets. /// Allocate and initialize a new Stream using the given base offsets.
static index_stream * static index_stream *
index_stream_init(lzma_vli compressed_base, lzma_vli uncompressed_base, index_stream_init(lzma_vli compressed_base, lzma_vli uncompressed_base,
lzma_vli stream_number, lzma_vli block_number_base, lzma_vli stream_number, lzma_vli block_number_base,
lzma_allocator *allocator) const lzma_allocator *allocator)
{ {
index_stream *s = lzma_alloc(sizeof(index_stream), allocator); index_stream *s = lzma_alloc(sizeof(index_stream), allocator);
if (s == NULL) if (s == NULL)
return NULL; return NULL;
s->node.uncompressed_base = uncompressed_base; s->node.uncompressed_base = uncompressed_base;
s->node.compressed_base = compressed_base; s->node.compressed_base = compressed_base;
s->node.parent = NULL; s->node.parent = NULL;
s->node.left = NULL; s->node.left = NULL;
s->node.right = NULL; s->node.right = NULL;
skipping to change at line 355 skipping to change at line 355
s->record_count = 0; s->record_count = 0;
s->index_list_size = 0; s->index_list_size = 0;
s->stream_flags.version = UINT32_MAX; s->stream_flags.version = UINT32_MAX;
s->stream_padding = 0; s->stream_padding = 0;
return s; return s;
} }
/// Free the memory allocated for a Stream and its Record groups. /// Free the memory allocated for a Stream and its Record groups.
static void static void
index_stream_end(void *node, lzma_allocator *allocator) index_stream_end(void *node, const lzma_allocator *allocator)
{ {
index_stream *s = node; index_stream *s = node;
index_tree_end(&s->groups, allocator, NULL); index_tree_end(&s->groups, allocator, NULL);
return; return;
} }
static lzma_index * static lzma_index *
index_init_plain(lzma_allocator *allocator) index_init_plain(const lzma_allocator *allocator)
{ {
lzma_index *i = lzma_alloc(sizeof(lzma_index), allocator); lzma_index *i = lzma_alloc(sizeof(lzma_index), allocator);
if (i != NULL) { if (i != NULL) {
index_tree_init(&i->streams); index_tree_init(&i->streams);
i->uncompressed_size = 0; i->uncompressed_size = 0;
i->total_size = 0; i->total_size = 0;
i->record_count = 0; i->record_count = 0;
i->index_list_size = 0; i->index_list_size = 0;
i->prealloc = INDEX_GROUP_SIZE; i->prealloc = INDEX_GROUP_SIZE;
i->checks = 0; i->checks = 0;
} }
return i; return i;
} }
extern LZMA_API(lzma_index *) extern LZMA_API(lzma_index *)
lzma_index_init(lzma_allocator *allocator) lzma_index_init(const lzma_allocator *allocator)
{ {
lzma_index *i = index_init_plain(allocator); lzma_index *i = index_init_plain(allocator);
if (i == NULL) if (i == NULL)
return NULL; return NULL;
index_stream *s = index_stream_init(0, 0, 1, 0, allocator); index_stream *s = index_stream_init(0, 0, 1, 0, allocator);
if (s == NULL) { if (s == NULL) {
lzma_free(i, allocator); lzma_free(i, allocator);
return NULL; return NULL;
} }
index_tree_append(&i->streams, &s->node); index_tree_append(&i->streams, &s->node);
return i; return i;
} }
extern LZMA_API(void) extern LZMA_API(void)
lzma_index_end(lzma_index *i, lzma_allocator *allocator) lzma_index_end(lzma_index *i, const lzma_allocator *allocator)
{ {
// NOTE: If you modify this function, check also the bottom // NOTE: If you modify this function, check also the bottom
// of lzma_index_cat(). // of lzma_index_cat().
if (i != NULL) { if (i != NULL) {
index_tree_end(&i->streams, allocator, &index_stream_end); index_tree_end(&i->streams, allocator, &index_stream_end);
lzma_free(i, allocator); lzma_free(i, allocator);
} }
return; return;
} }
skipping to change at line 605 skipping to change at line 605
if (lzma_index_file_size(i) + stream_padding > LZMA_VLI_MAX) { if (lzma_index_file_size(i) + stream_padding > LZMA_VLI_MAX) {
s->stream_padding = old_stream_padding; s->stream_padding = old_stream_padding;
return LZMA_DATA_ERROR; return LZMA_DATA_ERROR;
} }
s->stream_padding = stream_padding; s->stream_padding = stream_padding;
return LZMA_OK; return LZMA_OK;
} }
extern LZMA_API(lzma_ret) extern LZMA_API(lzma_ret)
lzma_index_append(lzma_index *i, lzma_allocator *allocator, lzma_index_append(lzma_index *i, const lzma_allocator *allocator,
lzma_vli unpadded_size, lzma_vli uncompressed_size) lzma_vli unpadded_size, lzma_vli uncompressed_size)
{ {
// Validate. // Validate.
if (i == NULL || unpadded_size < UNPADDED_SIZE_MIN if (i == NULL || unpadded_size < UNPADDED_SIZE_MIN
|| unpadded_size > UNPADDED_SIZE_MAX || unpadded_size > UNPADDED_SIZE_MAX
|| uncompressed_size > LZMA_VLI_MAX) || uncompressed_size > LZMA_VLI_MAX)
return LZMA_PROG_ERROR; return LZMA_PROG_ERROR;
index_stream *s = (index_stream *)(i->streams.rightmost); index_stream *s = (index_stream *)(i->streams.rightmost);
index_group *g = (index_group *)(s->groups.rightmost); index_group *g = (index_group *)(s->groups.rightmost);
skipping to change at line 730 skipping to change at line 730
index_tree_append(info->streams, &this->node); index_tree_append(info->streams, &this->node);
if (right != NULL) if (right != NULL)
index_cat_helper(info, right); index_cat_helper(info, right);
return; return;
} }
extern LZMA_API(lzma_ret) extern LZMA_API(lzma_ret)
lzma_index_cat(lzma_index *restrict dest, lzma_index *restrict src, lzma_index_cat(lzma_index *restrict dest, lzma_index *restrict src,
lzma_allocator *allocator) const lzma_allocator *allocator)
{ {
const lzma_vli dest_file_size = lzma_index_file_size(dest); const lzma_vli dest_file_size = lzma_index_file_size(dest);
// Check that we don't exceed the file size limits. // Check that we don't exceed the file size limits.
if (dest_file_size + lzma_index_file_size(src) > LZMA_VLI_MAX if (dest_file_size + lzma_index_file_size(src) > LZMA_VLI_MAX
|| dest->uncompressed_size + src->uncompressed_size || dest->uncompressed_size + src->uncompressed_size
> LZMA_VLI_MAX) > LZMA_VLI_MAX)
return LZMA_DATA_ERROR; return LZMA_DATA_ERROR;
// Check that the encoded size of the combined lzma_indexes stays // Check that the encoded size of the combined lzma_indexes stays
skipping to change at line 823 skipping to change at line 823
dest->checks = lzma_index_checks(dest) | src->checks; dest->checks = lzma_index_checks(dest) | src->checks;
// There's nothing else left in src than the base structure. // There's nothing else left in src than the base structure.
lzma_free(src, allocator); lzma_free(src, allocator);
return LZMA_OK; return LZMA_OK;
} }
/// Duplicate an index_stream. /// Duplicate an index_stream.
static index_stream * static index_stream *
index_dup_stream(const index_stream *src, lzma_allocator *allocator) index_dup_stream(const index_stream *src, const lzma_allocator *allocator)
{ {
// Catch a somewhat theoretical integer overflow. // Catch a somewhat theoretical integer overflow.
if (src->record_count > PREALLOC_MAX) if (src->record_count > PREALLOC_MAX)
return NULL; return NULL;
// Allocate and initialize a new Stream. // Allocate and initialize a new Stream.
index_stream *dest = index_stream_init(src->node.compressed_base, index_stream *dest = index_stream_init(src->node.compressed_base,
src->node.uncompressed_base, src->number, src->node.uncompressed_base, src->number,
src->block_number_base, allocator); src->block_number_base, allocator);
skipping to change at line 882 skipping to change at line 882
assert(i == destg->allocated); assert(i == destg->allocated);
// Add the group to the new Stream. // Add the group to the new Stream.
index_tree_append(&dest->groups, &destg->node); index_tree_append(&dest->groups, &destg->node);
return dest; return dest;
} }
extern LZMA_API(lzma_index *) extern LZMA_API(lzma_index *)
lzma_index_dup(const lzma_index *src, lzma_allocator *allocator) lzma_index_dup(const lzma_index *src, const lzma_allocator *allocator)
{ {
// Allocate the base structure (no initial Stream). // Allocate the base structure (no initial Stream).
lzma_index *dest = index_init_plain(allocator); lzma_index *dest = index_init_plain(allocator);
if (dest == NULL) if (dest == NULL)
return NULL; return NULL;
// Copy the totals. // Copy the totals.
dest->uncompressed_size = src->uncompressed_size; dest->uncompressed_size = src->uncompressed_size;
dest->total_size = src->total_size; dest->total_size = src->total_size;
dest->record_count = src->record_count; dest->record_count = src->record_count;
 End of changes. 11 change blocks. 
13 lines changed or deleted 15 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/