Re: Portability concerns over pq_sendbyte? - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: Portability concerns over pq_sendbyte?
Date
Msg-id 20180525020349.GB3078@paquier.xyz
Whole thread Raw
In response to Portability concerns over pq_sendbyte?  (Andrew Gierth <andrew@tao11.riddles.org.uk>)
List pgsql-hackers
On Thu, May 24, 2018 at 06:13:23PM +0100, Andrew Gierth wrote:
> In PG11, pq_sendbyte got changed from taking an int parameter to taking
> an int8.

From 1de09ad8.

> While that seems to work in general, it does mean that there are now
> several places in the code that do the equivalent of:
>
>     unsigned char x = 128;
>     pq_sendbyte(&buf, x);
>
> which I believe is not well-defined since pq_sendbyte takes an int8, and
> conversions of unrepresentable values to _signed_ integer types are
> (iirc) implementation-dependent.

Good point.

> There are also some cases where pq_sendint16 is being called for an
> unsigned value or a value that might exceed 32767.

If kept, some safeguards based on PG_INT*_[MIN|MAX] could be
appropriate.

> Would it be better for these to take unsigned values, or have unsigned
> variants?

It seems to me that it is not too late to change those interfaces so
as they use unsigned values in input so as they are consistent, it would
be dangerous on the contrary to keep those as they are.
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: "Jonathan S. Katz"
Date:
Subject: Re: Add PostgreSQL 11 to feature matrix page?
Next
From: "Higuchi, Daisuke"
Date:
Subject: RE: [Bug Fix]ECPG: cancellation of significant digits on ECPG