Skip to content

Commit

Permalink
jbig2dec: Work around exponentiation warning from clang.
Browse files Browse the repository at this point in the history
clang complains like so:

    jbig2_arith.c:258:17: warning: result of '10 ^ 9' is 3;
    did you mean '1e9'? [-Wxor-used-as-pow]
        {0x3801, 10 ^ 9, 14 ^ 9},

But 10 ^ 9 is indeed meant to be xor, not exponentiation.
The const values are identical to those in table E.1 in
the JBIG2 spec.

The workaround is to wrap everything in macros, adding extra
parenthesis, which causes the compiler warning not to trip.
  • Loading branch information
sebras committed Aug 28, 2023
1 parent bd26fa7 commit fbf863c
Showing 1 changed file with 50 additions and 47 deletions.
97 changes: 50 additions & 47 deletions jbig2_arith.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,54 +245,57 @@ typedef struct {
byte lps_xor; /* lps_xor = index ^ NLPS ^ (SWITCH << 7) */
} Jbig2ArithQe;

#define MPS(index, nmps) ((index) ^ (nmps))
#define LPS(index, nlps, swtch) ((index) ^ (nlps) ^ ((swtch) << 7))

static const Jbig2ArithQe jbig2_arith_Qe[MAX_QE_ARRAY_SIZE] = {
{0x5601, 1 ^ 0, 1 ^ 0 ^ 0x80},
{0x3401, 2 ^ 1, 6 ^ 1},
{0x1801, 3 ^ 2, 9 ^ 2},
{0x0AC1, 4 ^ 3, 12 ^ 3},
{0x0521, 5 ^ 4, 29 ^ 4},
{0x0221, 38 ^ 5, 33 ^ 5},
{0x5601, 7 ^ 6, 6 ^ 6 ^ 0x80},
{0x5401, 8 ^ 7, 14 ^ 7},
{0x4801, 9 ^ 8, 14 ^ 8},
{0x3801, 10 ^ 9, 14 ^ 9},
{0x3001, 11 ^ 10, 17 ^ 10},
{0x2401, 12 ^ 11, 18 ^ 11},
{0x1C01, 13 ^ 12, 20 ^ 12},
{0x1601, 29 ^ 13, 21 ^ 13},
{0x5601, 15 ^ 14, 14 ^ 14 ^ 0x80},
{0x5401, 16 ^ 15, 14 ^ 15},
{0x5101, 17 ^ 16, 15 ^ 16},
{0x4801, 18 ^ 17, 16 ^ 17},
{0x3801, 19 ^ 18, 17 ^ 18},
{0x3401, 20 ^ 19, 18 ^ 19},
{0x3001, 21 ^ 20, 19 ^ 20},
{0x2801, 22 ^ 21, 19 ^ 21},
{0x2401, 23 ^ 22, 20 ^ 22},
{0x2201, 24 ^ 23, 21 ^ 23},
{0x1C01, 25 ^ 24, 22 ^ 24},
{0x1801, 26 ^ 25, 23 ^ 25},
{0x1601, 27 ^ 26, 24 ^ 26},
{0x1401, 28 ^ 27, 25 ^ 27},
{0x1201, 29 ^ 28, 26 ^ 28},
{0x1101, 30 ^ 29, 27 ^ 29},
{0x0AC1, 31 ^ 30, 28 ^ 30},
{0x09C1, 32 ^ 31, 29 ^ 31},
{0x08A1, 33 ^ 32, 30 ^ 32},
{0x0521, 34 ^ 33, 31 ^ 33},
{0x0441, 35 ^ 34, 32 ^ 34},
{0x02A1, 36 ^ 35, 33 ^ 35},
{0x0221, 37 ^ 36, 34 ^ 36},
{0x0141, 38 ^ 37, 35 ^ 37},
{0x0111, 39 ^ 38, 36 ^ 38},
{0x0085, 40 ^ 39, 37 ^ 39},
{0x0049, 41 ^ 40, 38 ^ 40},
{0x0025, 42 ^ 41, 39 ^ 41},
{0x0015, 43 ^ 42, 40 ^ 42},
{0x0009, 44 ^ 43, 41 ^ 43},
{0x0005, 45 ^ 44, 42 ^ 44},
{0x0001, 45 ^ 45, 43 ^ 45},
{0x5601, 46 ^ 46, 46 ^ 46}
{0x5601, MPS(0, 1), LPS(0, 1, 1)},
{0x3401, MPS(1, 2), LPS(1, 6, 0)},
{0x1801, MPS(2, 3), LPS(2, 9, 0)},
{0x0AC1, MPS(3, 4), LPS(3, 12, 0)},
{0x0521, MPS(4, 5), LPS(4, 29, 0)},
{0x0221, MPS(5, 38), LPS(5, 33, 0)},
{0x5601, MPS(6, 7), LPS(6, 6, 1)},
{0x5401, MPS(7, 8), LPS(7, 14, 0)},
{0x4801, MPS(8, 9), LPS(8, 14, 0)},
{0x3801, MPS(9, 10), LPS(9, 14, 0)},
{0x3001, MPS(10, 11), LPS(10, 17, 0)},
{0x2401, MPS(11, 12), LPS(11, 18, 0)},
{0x1C01, MPS(12, 13), LPS(12, 20, 0)},
{0x1601, MPS(13, 29), LPS(13, 21, 0)},
{0x5601, MPS(14, 15), LPS(14, 14, 1)},
{0x5401, MPS(15, 16), LPS(15, 14, 0)},
{0x5101, MPS(16, 17), LPS(16, 15, 0)},
{0x4801, MPS(17, 18), LPS(17, 16, 0)},
{0x3801, MPS(18, 19), LPS(18, 17, 0)},
{0x3401, MPS(19, 20), LPS(19, 18, 0)},
{0x3001, MPS(20, 21), LPS(20, 19, 0)},
{0x2801, MPS(21, 22), LPS(21, 19, 0)},
{0x2401, MPS(22, 23), LPS(22, 20, 0)},
{0x2201, MPS(23, 24), LPS(23, 21, 0)},
{0x1C01, MPS(24, 25), LPS(24, 22, 0)},
{0x1801, MPS(25, 26), LPS(25, 23, 0)},
{0x1601, MPS(26, 27), LPS(26, 24, 0)},
{0x1401, MPS(27, 28), LPS(27, 25, 0)},
{0x1201, MPS(28, 29), LPS(28, 26, 0)},
{0x1101, MPS(29, 30), LPS(29, 27, 0)},
{0x0AC1, MPS(30, 31), LPS(30, 28, 0)},
{0x09C1, MPS(31, 32), LPS(31, 29, 0)},
{0x08A1, MPS(32, 33), LPS(32, 30, 0)},
{0x0521, MPS(33, 34), LPS(33, 31, 0)},
{0x0441, MPS(34, 35), LPS(34, 32, 0)},
{0x02A1, MPS(35, 36), LPS(35, 33, 0)},
{0x0221, MPS(36, 37), LPS(36, 34, 0)},
{0x0141, MPS(37, 38), LPS(37, 35, 0)},
{0x0111, MPS(38, 39), LPS(38, 36, 0)},
{0x0085, MPS(39, 40), LPS(39, 37, 0)},
{0x0049, MPS(40, 41), LPS(40, 38, 0)},
{0x0025, MPS(41, 42), LPS(41, 39, 0)},
{0x0015, MPS(42, 43), LPS(42, 40, 0)},
{0x0009, MPS(43, 44), LPS(43, 41, 0)},
{0x0005, MPS(44, 45), LPS(44, 42, 0)},
{0x0001, MPS(45, 45), LPS(45, 43, 0)},
{0x5601, MPS(46, 46), LPS(46, 46, 0)}
};

static int
Expand Down

0 comments on commit fbf863c

Please sign in to comment.