Skip to content

Commit

Permalink
Fix negative shift left reported by UBSan (#758)
Browse files Browse the repository at this point in the history
Follow-up of #757

This shall have no performance impact on 2’s complement machine where
the compiler replaces the multiplication by power of two (constant) by
a left shift.
Verified at least on MacOS Xcode 7.3, same assembly generated after fix.
  • Loading branch information
mayeut committed Apr 27, 2016
1 parent 2296dc9 commit e6881e7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib/openjp2/t1.c
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,7 @@ OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1,
if (tccp->qmfbid == 1) {
for (j = 0; j < cblk_h; ++j) {
for (i = 0; i < cblk_w; ++i) {
tiledp[tileIndex] *= 1 << T1_NMSEDEC_FRACBITS;
tiledp[tileIndex] *= (1 << T1_NMSEDEC_FRACBITS);
tileIndex++;
}
tileIndex += tileLineAdvance;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/openjp2/tcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1911,7 +1911,7 @@ static OPJ_BOOL opj_tcd_dc_level_shift_encode ( opj_tcd_t *p_tcd )
}
else {
for (i = 0; i < l_nb_elem; ++i) {
*l_current_ptr = (*l_current_ptr - l_tccp->m_dc_level_shift) << 11 ;
*l_current_ptr = (*l_current_ptr - l_tccp->m_dc_level_shift) * (1 << 11);
++l_current_ptr;
}
}
Expand Down

0 comments on commit e6881e7

Please sign in to comment.