diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 84f7e42373da4cf57daa19cd676cfb03bf9bd04b..f27992d05608ad5a41eb243bf6ea869b84c659f7 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -131,11 +131,11 @@ static void bastardized_rice_decompress(ALACContext *alac,
         sign_modifier = 0;
 
         /* now update the history */
-        history += x_modified * rice_history_mult -
-                    ((history * rice_history_mult) >> 9);
-
         if (x_modified > 0xffff)
             history = 0xffff;
+        else
+            history += x_modified * rice_history_mult -
+                        ((history * rice_history_mult) >> 9);
 
         /* special case: there may be compressed blocks of 0 */
         if ((history < 128) && (output_count+1 < output_size)) {