From 0a69e08c392b8373067e7b241a491d6798d82ad5 Mon Sep 17 00:00:00 2001 From: Harish Mahendrakar Date: Wed, 23 Nov 2016 13:15:19 +0530 Subject: [PATCH] Encoder: Fixed unaligned access of i1_ref_idx and u1_mv in cabac context i1_ref_idx and u1_mv in cabac context are defined as char, but were typecasted to int and were accessed, and were not aligned to 4 byte boundary. This results in an undefined behaviour Bug: 33073518 Test: Tested with -fsanitize=alignment enabled on avcenc Change-Id: Ie4a73de076a9239f2d8707af68b7d2cd796aa803 --- encoder/ih264e_cabac_init.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/encoder/ih264e_cabac_init.c b/encoder/ih264e_cabac_init.c index 347842c..7407dcc 100644 --- a/encoder/ih264e_cabac_init.c +++ b/encoder/ih264e_cabac_init.c @@ -160,17 +160,13 @@ void ih264e_init_cabac_table(entropy_ctxt_t *ps_ent_ctxt) /* 0th entry of mb_map_ctxt_inc will be always be containing default values */ /* for CABAC context representing MB not available */ mb_info_ctxt_t *ps_def_ctxt = ps_cabac_ctxt->ps_mb_map_ctxt_inc - 1; - UWORD32 *pu4_temp; - WORD8 i; ps_def_ctxt->u1_mb_type = CAB_SKIP; ps_def_ctxt->u1_cbp = 0x0f; ps_def_ctxt->u1_intrapred_chroma_mode = 0; - pu4_temp = (UWORD32 *)ps_def_ctxt->i1_ref_idx; - pu4_temp[0] = 0; - pu4_temp = (UWORD32 *)ps_def_ctxt->u1_mv; - for (i = 0; i < 4; i++, pu4_temp++) - (*pu4_temp) = 0; + + memset(ps_def_ctxt->i1_ref_idx, 0, sizeof(ps_def_ctxt->i1_ref_idx)); + memset(ps_def_ctxt->u1_mv, 0, sizeof(ps_def_ctxt->u1_mv)); ps_cabac_ctxt->ps_def_ctxt_mb_info = ps_def_ctxt; } }