diff --git a/src/bin/pg_xlogdump/compat.c b/src/bin/pg_xlogdump/compat.c
index 845c2e5234..165c2ae544 100644
--- a/src/bin/pg_xlogdump/compat.c
+++ b/src/bin/pg_xlogdump/compat.c
@@ -64,9 +64,10 @@ timestamptz_to_str(TimestampTz dt)
 	strftime(zone, sizeof(zone), "%Z", ltime);
 
 #ifdef HAVE_INT64_TIMESTAMP
-	sprintf(buf, "%s.%06d %s", ts, (int) (dt % USECS_PER_SEC), zone);
+	snprintf(buf, sizeof(buf), "%s.%06d %s",
+			 ts, (int) (dt % USECS_PER_SEC), zone);
 #else
-	sprintf(buf, "%s.%.6f %s", ts, fabs(dt - floor(dt)), zone);
+	snprintf(buf, sizeof(buf), "%s.%.6f %s", ts, fabs(dt - floor(dt)), zone);
 #endif
 
 	return buf;
