diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index d7c48bd4a35fd18d4a96193712de3fb3cd09542d..451a2af5bcb0db74ca602b17c13f47763a834c7a 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -6224,7 +6224,10 @@ decode_intra_mb:
         // FIXME The two following lines get the bitstream position in the cabac
         // decode, I think it should be done by a function in cabac.h (or cabac.c).
         ptr= h->cabac.bytestream;
-        if (h->cabac.low&0x1) ptr-=CABAC_BITS/8;
+        if(h->cabac.low&0x1) ptr--;
+        if(CABAC_BITS==16){
+            if(h->cabac.low&0x1FF) ptr--;
+        }
 
         // The pixels are stored in the same order as levels in h->mb array.
         for(y=0; y<16; y++){