Re: libpq support for NegotiateProtocolVersion

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Peter Eisentraut <peter(at)eisentraut(dot)org>, Jacob Champion <jchampion(at)timescale(dot)com>
Subject: Re: libpq support for NegotiateProtocolVersion
Date: 2025-04-03 13:08:48
Message-ID: c8860dd3-bd1c-44eb-89c3-28a6e850be1e@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 03/04/2025 14:55, Ranier Vilela wrote:
> Hi.
>
> Per Coverity.
>
> CID 1596094: (#1 of 1): Structurally dead code (UNREACHABLE)
> unreachable: Since the loop increment i++; is unreachable, the loop body
> will never execute more than once.

That is true, and I think we should just silence it. The loop is is
written that way in anticipation of future changes where libpq would
actually request some protocol extensions, but would be happy to
continue without server supporting them. But since we don't have any
yet, it's always an error if the server responded with any unsupported
protocol extensions.

> The code of the function *pqGetNegotiateProtocolVersion3* is a little
> confusing.
>
> I believe that the Coverity alert is valid.
> The function never returns 0.

It certainly does. It returns 0 when connecting to a pre-v18 server,
with the "max_protocol_version=3.2" option. In that case, the local
variable "num" is 0, the loop never executes, and the function returns 0.

--
Heikki Linnakangas
Neon (https://neon.tech)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jakub Wartak 2025-04-03 13:12:38 Re: Draft for basic NUMA observability
Previous Message Jakub Wartak 2025-04-03 12:42:32 Re: Draft for basic NUMA observability