From fe8938227e767ab85bc4f1d599032165aa2bf133 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 31 Jul 2017 10:05:04 -0400 Subject: [PATCH] tests/lzma: Fix off-by-one in buffer size Coverity spotted that we had an off-by-one here since we were using `i+1`. Fix this by adding a `-1` to the bounds check. Also use `sizeof()` to ensure the data and size are coupled. Coverity CID: 1452207 Closes: #1037 Approved by: jlebon --- tests/test-lzma.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test-lzma.c b/tests/test-lzma.c index b3487ee3..559e9ad4 100644 --- a/tests/test-lzma.c +++ b/tests/test-lzma.c @@ -79,13 +79,12 @@ static void test_lzma_random (void) { gssize i; - const guint32 buffer_size = 4096 + 1; - guint8 buffer[buffer_size]; + guint8 buffer[4096]; g_autoptr(GRand) r = g_rand_new (); - for (i = 0; i < buffer_size; i++) + for (i = 0; i < sizeof(buffer); i++) buffer[i] = g_rand_int (r); - for (i = 2; i <= buffer_size; i *= 2) + for (i = 2; i < (sizeof(buffer) - 1); i *= 2) { helper_test_compress_decompress (buffer, i - 1); helper_test_compress_decompress (buffer, i);