pgoff_t is most likely a 64-bit integer, so casting it to a 32-bit
type for output could lose data. In the cases addressed here, the
files cannot actually get that large, so this is only cosmetic and to
set better examples for the future. (Similar issues that could have
actual practical impact were addressed separately in commit
e8f851d6172.)
In one case, the 32-bit size is baked into the protocol, so here we
add an elog and document this discrepancy.
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/
20ce62fa-47fc-457b-b504-
12f3c1651726%40eisentraut.org
if (ftruncate(fd, xlrec->offset) != 0)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not truncate file \"%s\" to %u: %m",
- path, (uint32) xlrec->offset)));
+ errmsg("could not truncate file \"%s\" to %lld: %m",
+ path, (long long int) xlrec->offset)));
pgstat_report_wait_end();
data = XLogRecGetData(r) + sizeof(*xlrec);
if (nbytes != length)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not write file \"%s\": wrote only %d of %d bytes at offset %u",
+ errmsg("could not write file \"%s\": wrote only %d of %d bytes at offset %lld",
FilePathName(io->file), nbytes,
- length, (unsigned) io->filepos),
+ length, (long long) io->filepos),
errhint("Check free disk space.")));
io->filepos += nbytes;
(errcode_for_file_access(),
errmsg("could not seek to beginning of file \"%s\": %m", path)));
+ /*
+ * unlikely in practice, but to document the implicit integer conversion
+ */
+ if (histfilelen > UINT32_MAX)
+ elog(ERROR, "timeline history file is too large");
+
pq_sendint32(&buf, histfilelen); /* col2 len */
bytesleft = histfilelen;
{
if ((size / 1024) >= log_temp_files)
ereport(LOG,
- (errmsg("temporary file: path \"%s\", size %lu",
- path, (unsigned long) size)));
+ (errmsg("temporary file: path \"%s\", size %lld",
+ path, (long long) size)));
}
}
if (rc == 0)
{
/* unexpected EOF */
- pg_log(PG_WARNING, "unexpected EOF reading file \"%s\" at offset %u, reading as zeros",
- state->fn, (unsigned int) offset);
+ pg_log(PG_WARNING, "unexpected EOF reading file \"%s\" at offset %lld, reading as zeros",
+ state->fn, (long long int) offset);
memset(&state->buf.data[bytes_read], 0, BLCKSZ - bytes_read);
break;
}