avcodec/mjpegdec: Reorder operations to avoid undefined behavior