Skip to content

Commit ff1b207

Browse files
committed
Fix yet another shift of negative value.
1 parent 8423419 commit ff1b207

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

guetzli/jpeg_data_reader.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ namespace {
6363
return false; \
6464
}
6565

66+
inline int SignedLeftshift(int v, int s) {
67+
return (v >= 0) ? (v << s) : -((-v) << s);
68+
}
69+
6670
// Returns ceil(a/b).
6771
inline int DivCeil(int a, int b) {
6872
return (a + b - 1) / b;
@@ -520,7 +524,7 @@ int ReadSymbol(const HuffmanTableEntry* table, BitReaderState* br) {
520524
// Returns the DC diff or AC value for extra bits value x and prefix code s.
521525
// See Tables F.1 and F.2 of the spec.
522526
int HuffExtend(int x, int s) {
523-
return (x < (1 << (s - 1)) ? x - ((1) << s ) + 1 : x);
527+
return (x < (1 << (s - 1)) ? x - (1 << s) + 1 : x);
524528
}
525529

526530
// Decodes one 8x8 block of DCT coefficients from the bit stream.
@@ -590,7 +594,7 @@ bool DecodeDCTBlock(const HuffmanTableEntry* dc_huff,
590594
}
591595
r = br->ReadBits(s);
592596
s = HuffExtend(r, s);
593-
coeffs[kJPEGNaturalOrder[k]] = s << Al;
597+
coeffs[kJPEGNaturalOrder[k]] = SignedLeftshift(s, Al);
594598
} else if (r == 15) {
595599
k += 15;
596600
} else {

0 commit comments

Comments
 (0)