diff --git a/libavcodec/fitsdec.c b/libavcodec/fitsdec.c
index 8ede0bcbfad4f20865db4cc363d9c76fc81b32a9..b0753813c9c92419b6318d5787b13132f1fbc19f 100644
--- a/libavcodec/fitsdec.c
+++ b/libavcodec/fitsdec.c
@@ -264,11 +264,10 @@ static int fits_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
             for (j = 0; j < avctx->width; j++) { \
                 t = rd; \
                 if (!header.blank_found || t != header.blank) { \
-                    t = ((t - header.data_min) * ((1 << (sizeof(type) * 8)) - 1)) / (header.data_max - header.data_min); \
+                    *dst++ = ((t - header.data_min) * ((1 << (sizeof(type) * 8)) - 1)) / (header.data_max - header.data_min); \
                 } else { \
-                    t = fitsctx->blank_val; \
+                    *dst++ = fitsctx->blank_val; \
                 } \
-                *dst++ = (type) t; \
                 ptr8 += abs(cas) >> 3; \
             } \
         } \