diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 263a66d68eb87a19c2f072d648f7630e11d7c5b0..66efce07ee4cbb110f8f662567419bdf1490f746 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -3849,7 +3849,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
     h->slice_type= slice_type;
 
     s->pict_type= h->slice_type; // to make a few old func happy, it's wrong though
-    if (s->pict_type == B_TYPE && s->last_picture_ptr == NULL) {
+    if (s->pict_type == B_TYPE && s0->last_picture_ptr == NULL) {
         av_log(h->s.avctx, AV_LOG_ERROR,
                "B picture before any references, skipping\n");
         return -1;