Replace %ld with %jd and cast to intmax_t