1--- jcphuff.c
2+++ jcphuff.c
3@@ -14,6 +14,7 @@
4  * suspension.
5  */
6
7+#include <stdint.h>
8 #define JPEG_INTERNALS
9 #include "jinclude.h"
10 #include "jpeglib.h"
11@@ -255,7 +256,7 @@
12     if (c == 0xFF) {            /* need to stuff a zero byte? */
13       emit_byte(entropy, 0);
14     }
15-    put_buffer <<= 8;
16+    put_buffer = (uint_least32_t) put_buffer << 8;
17     put_bits -= 8;
18   }
19
20--- jdarith.c
21+++ jdarith.c
22@@ -306,7 +306,7 @@
23       while (m >>= 1)
24         if (arith_decode(cinfo, st)) v |= m;
25       v += 1; if (sign) v = -v;
26-      entropy->last_dc_val[ci] += v;
27+      entropy->last_dc_val[ci] = (entropy->last_dc_val[ci] + v) & 0xffff;
28     }
29
30     /* Scale and output the DC coefficient (assumes jpeg_natural_order[0]=0) */
31@@ -564,7 +564,7 @@
32       while (m >>= 1)
33         if (arith_decode(cinfo, st)) v |= m;
34       v += 1; if (sign) v = -v;
35-      entropy->last_dc_val[ci] += v;
36+      entropy->last_dc_val[ci] = (entropy->last_dc_val[ci] + v) & 0xffff;
37     }
38
39     if (block)
40