From 43f058366f858d6d00b04004f280fa819c694a83 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 8 May 2025 18:34:56 +0200 Subject: [PATCH] Fix PQport to never return NULL unless the connection is NULL This is the documented behaviour, but, at the moment, if the port in the connection string is an empty string, the port is returned as NULL by this function. --- src/interfaces/libpq/fe-connect.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 09eb79812ac6..c5f8655c19dd 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -7528,7 +7528,9 @@ PQport(const PGconn *conn) if (!conn) return NULL; - if (conn->connhost != NULL) + if (conn->connhost != NULL && + conn->connhost[conn->whichhost].port != NULL && + conn->connhost[conn->whichhost].port[0] != '\0') return conn->connhost[conn->whichhost].port; return "";