Re: truncating casts of pgoff_t

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: truncating casts of pgoff_t
Date: 2026-06-22 09:29:10
Message-ID: 45C1DF95-2A9F-40DA-B702-E74C81305F9B@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Jun 22, 2026, at 15:56, Peter Eisentraut <peter(at)eisentraut(dot)org> wrote:
>
> I found a couple of places where a pgoff_t value, typically a signed 64-bit integer, is cast to a type with a smaller range. I noticed this specifically in error messages, so it's mostly cosmetic. Also, files with a size where this would matter are not expected in many places, but I suspect that the case in basebackup_server.c in the attached patch can actually happen.
>
> The fix is to use the %lld print format and a cast to long long int, which is the style already in most places.
>
> In passing, I also converted a few places that used %llu to print pgoff_t to also use %lld instead. This is mostly for consistency, but it also feels more robust in case a negative value ever sneaks in.
> <0001-Don-t-cast-pgoff_t-to-possibly-32-bit-types-for-outp.patch><0002-Print-off_t-pgoff_t-consistently-as-lld.patch>

I have small comment:

walsender.c
```
+ /* XXX might truncate histfilelen */
+ Assert(histfilelen <= UINT32_MAX);
```

histfilelen is returned from lseek(), that’s a runtime behavior. I’m afraid Assert is weak here. If we really worry about the truncate, should we use elog(ERROR).

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2026-06-22 09:34:53 psql: Fix CREATE SCHEMA scanning of nested routine bodies
Previous Message shveta malik 2026-06-22 09:21:43 Re: Proposal: Conflict log history table for Logical Replication