aboutsummaryrefslogtreecommitdiff
path: root/tests/test_index.c
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2015-10-12 21:07:41 +0300
committerLasse Collin <lasse.collin@tukaani.org>2015-10-12 21:07:41 +0300
commit372e402713a1d4337ffce5f56d5c5c9ed99a66d0 (patch)
treeacb739bc1ef80108c1931cc322549857d69cad48 /tests/test_index.c
parentliblzma: Fix lzma_index_dup() for empty Streams. (diff)
downloadxz-372e402713a1d4337ffce5f56d5c5c9ed99a66d0.tar.xz
Tests: Add tests for the two bugs fixed in index.c.
Diffstat (limited to 'tests/test_index.c')
-rw-r--r--tests/test_index.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/test_index.c b/tests/test_index.c
index 06b4d6ba..ce2cfe10 100644
--- a/tests/test_index.c
+++ b/tests/test_index.c
@@ -630,6 +630,22 @@ test_corrupt(void)
}
+// Allocator that succeeds for the first two allocation but fails the rest.
+static void *
+my_alloc(void *opaque, size_t a, size_t b)
+{
+ (void)opaque;
+
+ static unsigned count = 0;
+ if (++count > 2)
+ return NULL;
+
+ return malloc(a * b);
+}
+
+static const lzma_allocator my_allocator = { &my_alloc, NULL, NULL };
+
+
int
main(void)
{
@@ -655,5 +671,19 @@ main(void)
test_corrupt();
+ // Test for the bug fix 21515d79d778b8730a434f151b07202d52a04611:
+ // liblzma: Fix lzma_index_dup() for empty Streams.
+ i = create_empty();
+ expect(lzma_index_stream_padding(i, 4) == LZMA_OK);
+ test_copy(i);
+ lzma_index_end(i, NULL);
+
+ // Test for the bug fix 3bf857edfef51374f6f3fffae3d817f57d3264a0:
+ // liblzma: Fix a memory leak in error path of lzma_index_dup().
+ // Use Valgrind to see that there are no leaks.
+ i = create_small();
+ expect(lzma_index_dup(i, &my_allocator) == NULL);
+ lzma_index_end(i, NULL);
+
return 0;
}