suppress valgrind error - avoid accessing uninitialized memory in mq encoder

This commit is contained in:
Aaron Boxer 2016-01-30 10:05:46 -05:00
parent e3100f714c
commit 0069a2bd2f
1 changed files with 9 additions and 3 deletions

View File

@ -203,14 +203,20 @@ static opj_mqc_state_t mqc_states[47 * 2] = {
*/ */
static void opj_mqc_byteout(opj_mqc_t *mqc) { static void opj_mqc_byteout(opj_mqc_t *mqc) {
OPJ_BYTE bp_in_bounds = (mqc->bp >= mqc->start); /* avoid accessing uninitialized memory*/
if (bp_in_bounds & (*mqc->bp == 0xff)) { if (mqc->bp == mqc->start-1) {
mqc->bp++;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 19);
mqc->c &= 0x7ffff;
mqc->ct = 8;
}
else if (*mqc->bp == 0xff) {
mqc->bp++; mqc->bp++;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 20); *mqc->bp = (OPJ_BYTE)(mqc->c >> 20);
mqc->c &= 0xfffff; mqc->c &= 0xfffff;
mqc->ct = 7; mqc->ct = 7;
} else { } else {
if ((bp_in_bounds ^ 1) | ((mqc->c & 0x8000000) == 0)) { if ((mqc->c & 0x8000000) == 0) {
mqc->bp++; mqc->bp++;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 19); *mqc->bp = (OPJ_BYTE)(mqc->c >> 19);
mqc->c &= 0x7ffff; mqc->c &= 0x7ffff;