Re: Portability concerns over pq_sendbyte?

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Portability concerns over pq_sendbyte?
Date: 2018-05-25 02:03:49
Message-ID: 20180525020349.GB3078@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2018-05-25 02:09:20 Re: Add PostgreSQL 11 to feature matrix page?
Previous Message Jonathan S. Katz 2018-05-25 01:52:35 Re: Add PostgreSQL 11 to feature matrix page?