From 1c3273aab24c1626faf552c9f4be7c7847e431a9 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 14 May 2012 14:38:02 +0000 Subject: [PATCH] [trunk] Make sure the memory is initialized. valgrind was complaning in mqc_init_enc we were reading uninit value. See also comment in r479: FIXME: mqc_init_enc and mqc_byteout underrun the buffer if we don't do this. Why? --- libopenjpeg/tcd.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libopenjpeg/tcd.c b/libopenjpeg/tcd.c index 2ac9199a..1fc97a80 100644 --- a/libopenjpeg/tcd.c +++ b/libopenjpeg/tcd.c @@ -437,6 +437,8 @@ void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int c cblk->y1 = int_min(cblkyend, prc->y1); cblk->data = (unsigned char*) opj_calloc(8192+2, sizeof(unsigned char)); /* FIXME: mqc_init_enc and mqc_byteout underrun the buffer if we don't do this. Why? */ + cblk->data[0] = 0; + cblk->data[1] = 0; cblk->data += 2; cblk->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof(opj_tcd_layer_t)); cblk->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(opj_tcd_pass_t)); @@ -696,6 +698,8 @@ void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int cur cblk->y1 = int_min(cblkyend, prc->y1); cblk->data = (unsigned char*) opj_calloc(8192+2, sizeof(unsigned char)); /* FIXME: mqc_init_enc and mqc_byteout underrun the buffer if we don't do this. Why? */ + cblk->data[0] = 0; + cblk->data[1] = 0; cblk->data += 2; cblk->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof(opj_tcd_layer_t)); cblk->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(opj_tcd_pass_t)); @@ -2425,6 +2429,7 @@ opj_bool tcd_code_block_enc_allocate (opj_tcd_cblk_enc_v2_t * p_code_block) return OPJ_FALSE; } + p_code_block->data[0] = 0; p_code_block->data+=1; /* no memset since data */