diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
index 9f82c7418141a4d99c1f1085a20e02db0701ee9e..66607ada21e200322ef39106ed56563bb16a3b4d 100644
--- a/libavcodec/golomb.h
+++ b/libavcodec/golomb.h
@@ -187,7 +187,11 @@ static inline int get_se_golomb(GetBitContext *gb){
 
         return ff_se_golomb_vlc_code[buf];
     }else{
-        log= 2*av_log2(buf) - 31;
+        log = av_log2(buf);
+        LAST_SKIP_BITS(re, gb, 31 - log);
+        UPDATE_CACHE(re, gb);
+        buf = GET_CACHE(re, gb);
+
         buf>>= log;
 
         LAST_SKIP_BITS(re, gb, 32 - log);