Commit 65ac1e61 by Benjamin Barenblat Committed by Copybara-Service

Avoid signedness change when casting off_t

Some ABSL_RAW_LOG statements print off_t values by casting them to
uintmax_t. However, POSIX says off_t is signed [1], so intmax_t is more
appropriate. Replace casts and format specifiers as needed.

[1] https://pubs.opengroup.org/onlinepubs/009696899/basedefs/sys/types.h.html#:~:text=off_t%20shall,%20types%2e

PiperOrigin-RevId: 461684406
Change-Id: I09ec1a3ba49cd688670618797943a84bc48dba3e
parent 6162604b
...@@ -442,8 +442,8 @@ static ssize_t ReadFromOffset(const int fd, void *buf, const size_t count, ...@@ -442,8 +442,8 @@ static ssize_t ReadFromOffset(const int fd, void *buf, const size_t count,
const off_t offset) { const off_t offset) {
off_t off = lseek(fd, offset, SEEK_SET); off_t off = lseek(fd, offset, SEEK_SET);
if (off == (off_t)-1) { if (off == (off_t)-1) {
ABSL_RAW_LOG(WARNING, "lseek(%d, %ju, SEEK_SET) failed: errno=%d", fd, ABSL_RAW_LOG(WARNING, "lseek(%d, %jd, SEEK_SET) failed: errno=%d", fd,
static_cast<uintmax_t>(offset), errno); static_cast<intmax_t>(offset), errno);
return -1; return -1;
} }
return ReadPersistent(fd, buf, count); return ReadPersistent(fd, buf, count);
...@@ -492,9 +492,9 @@ static ABSL_ATTRIBUTE_NOINLINE bool GetSectionHeaderByType( ...@@ -492,9 +492,9 @@ static ABSL_ATTRIBUTE_NOINLINE bool GetSectionHeaderByType(
if (len % sizeof(buf[0]) != 0) { if (len % sizeof(buf[0]) != 0) {
ABSL_RAW_LOG( ABSL_RAW_LOG(
WARNING, WARNING,
"Reading %zd bytes from offset %ju returned %zd which is not a " "Reading %zd bytes from offset %jd returned %zd which is not a "
"multiple of %zu.", "multiple of %zu.",
num_bytes_to_read, static_cast<uintmax_t>(offset), len, num_bytes_to_read, static_cast<intmax_t>(offset), len,
sizeof(buf[0])); sizeof(buf[0]));
return false; return false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment