Fix negative shift left reported by UBSan (#757)
authorMatthieu Darbois <mayeut@users.noreply.github.com>
Tue, 26 Apr 2016 20:06:06 +0000 (22:06 +0200)
committerMatthieu Darbois <mayeut@users.noreply.github.com>
Tue, 26 Apr 2016 20:06:06 +0000 (22:06 +0200)
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.

src/lib/openjp2/t1.c

index 108ce78b603ca9eac60b533ec4386f91077135cc..8d020bb52911845ce5af898806e9b5c1b3d63fb0 100644 (file)
@@ -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] <<= T1_NMSEDEC_FRACBITS;
+                                                                       tiledp[tileIndex] *= 1 << T1_NMSEDEC_FRACBITS;
                                                                        tileIndex++;
                                                                }
                                                                tileIndex += tileLineAdvance;