diff --git a/common/bitstream.c b/common/bitstream.c
index c45f86251bf4c80637496e1bf3547d8bc6c35930..60459b703030fc700779592ace8738e46c491a2a 100644
--- a/common/bitstream.c
+++ b/common/bitstream.c
@@ -92,10 +92,10 @@ void x264_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal )
     {
         /* Size doesn't include the size of the header we're writing now. */
         int chunk_size = size - 4;
-        orig_dst[0] = chunk_size >> 24;
-        orig_dst[1] = chunk_size >> 16;
-        orig_dst[2] = chunk_size >> 8;
-        orig_dst[3] = chunk_size >> 0;
+        orig_dst[0] = (uint8_t)(chunk_size >> 24);
+        orig_dst[1] = (uint8_t)(chunk_size >> 16);
+        orig_dst[2] = (uint8_t)(chunk_size >> 8);
+        orig_dst[3] = (uint8_t)(chunk_size >> 0);
     }
 
     nal->i_payload = size;
diff --git a/common/cabac.c b/common/cabac.c
index 9c699953c66b95c9e5cb24c038b0f4abd83b9b32..010580d5ce564053265aa050ded60905b51b5f1d 100644
--- a/common/cabac.c
+++ b/common/cabac.c
@@ -89,10 +89,10 @@ static inline void cabac_putbyte( x264_cabac_t *cb )
             cb->p[-1] += carry;
             while( bytes_outstanding > 0 )
             {
-                *(cb->p++) = carry-1;
+                *(cb->p++) = (uint8_t)(carry-1);
                 bytes_outstanding--;
             }
-            *(cb->p++) = out;
+            *(cb->p++) = (uint8_t)out;
             cb->i_bytes_outstanding = 0;
         }
     }
diff --git a/common/mc.h b/common/mc.h
index 4b55dbfe6f5195ce391674092d80c634878d2c9f..8c12b9e0c5f483d66b09c575fb8be101520018a9 100644
--- a/common/mc.h
+++ b/common/mc.h
@@ -61,8 +61,8 @@ static void mbtree_propagate_list_##cpu( x264_t *h, uint16_t *ref_costs, int16_t
             if( !(lowres_costs[i] & (1 << (list+LOWRES_COST_SHIFT))) )\
                 continue;\
 \
-            unsigned mbx = current[0];\
-            unsigned mby = current[1];\
+            unsigned mbx = (unsigned)current[0];\
+            unsigned mby = (unsigned)current[1];\
             unsigned idx0 = mbx + mby * stride;\
             unsigned idx2 = idx0 + stride;\
 \
diff --git a/common/mvpred.c b/common/mvpred.c
index 42d792f50aa66ca9a92a6c1b36758c45fbe8d81b..c00dc9dfe33430905a7c9c823fe83ab05eaffc2e 100644
--- a/common/mvpred.c
+++ b/common/mvpred.c
@@ -171,8 +171,8 @@ void x264_mb_predict_mv_pskip( x264_t *h, int16_t mv[2] )
     int16_t *mv_b  = h->mb.cache.mv[0][X264_SCAN8_0 - 8];
 
     if( i_refa == -2 || i_refb == -2 ||
-        !( i_refa | M32( mv_a ) ) ||
-        !( i_refb | M32( mv_b ) ) )
+        !( (uint32_t)i_refa | M32( mv_a ) ) ||
+        !( (uint32_t)i_refb | M32( mv_b ) ) )
     {
         M32( mv ) = 0;
     }
@@ -304,7 +304,7 @@ static ALWAYS_INLINE int mb_predict_mv_direct16x16_spatial( x264_t *h, int b_int
             mv_c   = h->mb.cache.mv[i_list][X264_SCAN8_0 - 8 - 1];
         }
 
-        int i_ref = X264_MIN3( (unsigned)i_refa, (unsigned)i_refb, (unsigned)i_refc );
+        int i_ref = (int)X264_MIN3( (unsigned)i_refa, (unsigned)i_refb, (unsigned)i_refc );
         if( i_ref < 0 )
         {
             i_ref = -1;
diff --git a/common/rectangle.h b/common/rectangle.h
index 07583df584a6e5a3b163dcb6fb4ed7e43c7c6ad7..3849c03200d5c49c774941a2a1b595e6c0540d1c 100644
--- a/common/rectangle.h
+++ b/common/rectangle.h
@@ -28,8 +28,8 @@
 static ALWAYS_INLINE void x264_macroblock_cache_rect( void *dst, int w, int h, int s, uint32_t v )
 {
     uint8_t *d = dst;
-    uint16_t v2 = s == 2 ? v : v * 0x101;
-    uint32_t v4 = s == 4 ? v : s == 2 ? v * 0x10001 : v * 0x1010101;
+    uint16_t v2 = s >= 2 ? v : v * 0x101;
+    uint32_t v4 = s >= 4 ? v : s >= 2 ? v * 0x10001 : v * 0x1010101;
     uint64_t v8 = v4 + ((uint64_t)v4 << 32);
     s *= 8;
 
@@ -142,13 +142,13 @@ static ALWAYS_INLINE void x264_macroblock_cache_mvd( x264_t *h, int x, int y, in
     else
         x264_macroblock_cache_rect( mvd_cache, width*2, height, 2, mvd );
 }
-static ALWAYS_INLINE void x264_macroblock_cache_ref( x264_t *h, int x, int y, int width, int height, int i_list, uint8_t ref )
+static ALWAYS_INLINE void x264_macroblock_cache_ref( x264_t *h, int x, int y, int width, int height, int i_list, int8_t ref )
 {
     void *ref_cache = &h->mb.cache.ref[i_list][X264_SCAN8_0+x+8*y];
     if( x264_nonconstant_p( width ) || x264_nonconstant_p( height ) )
-        x264_cache_ref_func_table[width + (height<<1)-3]( ref_cache, ref );
+        x264_cache_ref_func_table[width + (height<<1)-3]( ref_cache, (uint8_t)ref );
     else
-        x264_macroblock_cache_rect( ref_cache, width, height, 1, ref );
+        x264_macroblock_cache_rect( ref_cache, width, height, 1, (uint8_t)ref );
 }
 static ALWAYS_INLINE void x264_macroblock_cache_skip( x264_t *h, int x, int y, int width, int height, int b_skip )
 {
diff --git a/common/x86/util.h b/common/x86/util.h
index c057298a4dfef3f54a6a4cc60d125a7d65dd8869..77a99313bec09bbc5c89cb0bced07e680d54d8f3 100644
--- a/common/x86/util.h
+++ b/common/x86/util.h
@@ -121,7 +121,7 @@ static ALWAYS_INLINE uint16_t x264_cabac_mvd_sum_mmx2(uint8_t *mvdleft, uint8_t
          "m"(pb_2),"m"(pb_32),"m"(pb_33)
         :"mm0", "mm1", "mm2"
     );
-    return amvd;
+    return (uint16_t)amvd;
 }
 
 #define x264_predictor_clip x264_predictor_clip_mmx2
diff --git a/output/matroska_ebml.c b/output/matroska_ebml.c
index b269437c61865910ea2225f4aa1bb61e981412c2..d5b9b1d66b5733d4f797ca2109421bc86e96d20b 100644
--- a/output/matroska_ebml.c
+++ b/output/matroska_ebml.c
@@ -60,7 +60,7 @@ struct mk_writer
     int64_t cluster_tc_scaled;
     int64_t frame_tc, max_frame_tc;
 
-    char wrote_header, in_frame, keyframe, skippable;
+    int8_t wrote_header, in_frame, keyframe, skippable;
 };
 
 static mk_context *mk_create_context( mk_writer *w, mk_context *parent, unsigned id )
@@ -111,7 +111,7 @@ static int mk_append_context_data( mk_context *c, const void *data, unsigned siz
         c->d_max = dn;
     }
 
-    memcpy( (char*)c->data + c->d_cur, data, size );
+    memcpy( (uint8_t*)c->data + c->d_cur, data, size );
 
     c->d_cur = ns;
 
@@ -120,7 +120,7 @@ static int mk_append_context_data( mk_context *c, const void *data, unsigned siz
 
 static int mk_write_id( mk_context *c, unsigned id )
 {
-    unsigned char c_id[4] = { id >> 24, id >> 16, id >> 8, id };
+    uint8_t c_id[4] = { id >> 24, id >> 16, id >> 8, id };
 
     if( c_id[0] )
         return mk_append_context_data( c, c_id, 4 );
@@ -133,7 +133,7 @@ static int mk_write_id( mk_context *c, unsigned id )
 
 static int mk_write_size( mk_context *c, unsigned size )
 {
-    unsigned char c_size[5] = { 0x08, size >> 24, size >> 16, size >> 8, size };
+    uint8_t c_size[5] = { 0x08, size >> 24, size >> 16, size >> 8, size };
 
     if( size < 0x7f )
     {
@@ -160,7 +160,7 @@ static int mk_write_size( mk_context *c, unsigned size )
 
 static int mk_flush_context_id( mk_context *c )
 {
-    unsigned char ff = 0xff;
+    uint8_t ff = 0xff;
 
     if( !c->id )
         return 0;
@@ -249,9 +249,9 @@ static int mk_write_bin( mk_context *c, unsigned id, const void *data, unsigned
     return 0;
 }
 
-static int mk_write_uint( mk_context *c, unsigned id, int64_t ui )
+static int mk_write_uint( mk_context *c, unsigned id, uint64_t ui )
 {
-    unsigned char c_ui[8] = { ui >> 56, ui >> 48, ui >> 40, ui >> 32, ui >> 24, ui >> 16, ui >> 8, ui };
+    uint8_t c_ui[8] = { ui >> 56, ui >> 48, ui >> 40, ui >> 32, ui >> 24, ui >> 16, ui >> 8, ui };
     unsigned i = 0;
 
     CHECK( mk_write_id( c, id ) );
@@ -267,9 +267,9 @@ static int mk_write_float_raw( mk_context *c, float f )
     union
     {
         float f;
-        unsigned u;
+        uint32_t u;
     } u;
-    unsigned char c_f[4];
+    uint8_t c_f[4];
 
     u.f = f;
     c_f[0] = u.u >> 24;
@@ -408,7 +408,7 @@ static int mk_flush_frame( mk_writer *w )
 {
     int64_t delta;
     unsigned fsize;
-    unsigned char c_delta_flags[3];
+    uint8_t c_delta_flags[3];
 
     if( !w->in_frame )
         return 0;
@@ -435,8 +435,8 @@ static int mk_flush_frame( mk_writer *w )
     CHECK( mk_write_size( w->cluster, fsize + 4 ) ); // Size
     CHECK( mk_write_size( w->cluster, 1 ) ); // TrackNumber
 
-    c_delta_flags[0] = delta >> 8;
-    c_delta_flags[1] = delta;
+    c_delta_flags[0] = (uint8_t)(delta >> 8);
+    c_delta_flags[1] = (uint8_t)delta;
     c_delta_flags[2] = (w->keyframe << 7) | w->skippable;
     CHECK( mk_append_context_data( w->cluster, c_delta_flags, 3 ) ); // Timecode, Flags
     if( w->frame )