pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Lionel Elie Mamane <lionel@mamane.lu>
To: pgsql-bugs@postgresql.org
Subject: BUG #6216: Calling PQconnectdbParams from C++ with a char**
Date: Tue, 20 Sep 2011 16:05:55 GMT
Message-ID: <201109201605.p8KG5tku049175@wwwmaster.postgresql.org> (raw)


The following bug has been logged online:

Bug reference:      6216
Logged by:          Lionel Elie Mamane
Email address:      lionel@mamane.lu
PostgreSQL version: 9.1.0
Operating system:   Debian GNU/Linux
Description:        Calling PQconnectdbParams from C++ with a char**
Details: 

In C++, a "char**" value is not convertible to a "const char**" value,
because that is not safe (see
http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.17).

This means one cannot call libpq's PQconnectdbParams and friends passing
them a "char**" value for keywords and/or values, as these arguments are
declared "const char**".

So please apply this patch, which declares them "char const* const*"
instead, which is:
 - equivalent to "const char * const*"; use that one if you prefer
 - still true, since libpq won't write to they keyword/values arrays
 - allows to pass a "char**" to them and be recognised by a C++ compiler as
OK without a cast.

This patch is licensed under a "do whatever you want with it" license.

Thanks in advance.


inline patch 1: postgresql-9.1-9.1.0/src/interfaces/libpq/fe-connect.c (+4/-4 lines) download inline-1.patch--- postgresql-9.1-9.1.0.orig/src/interfaces/libpq/fe-connect.c +++ postgresql-9.1-9.1.0/src/interfaces/libpq/fe-connect.c @@ -291,8 +291,8 @@ static void freePGconn(PGconn *conn); static void closePGconn(PGconn *conn); static PQconninfoOption *conninfo_parse(const char *conninfo, PQExpBuffer errorMessage, bool use_defaults); -static PQconninfoOption *conninfo_array_parse(const char **keywords, - const char **values, PQExpBuffer errorMessage, +static PQconninfoOption *conninfo_array_parse(char const* const*keywords, + char const* const*values, PQExpBuffer errorMessage, bool use_defaults, int expand_dbname); static char *conninfo_getval(PQconninfoOption *connOptions, const char *keyword); @@ -362,8 +362,8 @@ pgthreadlock_t pg_g_threadlock = default * call succeeded. */ PGconn * -PQconnectdbParams(const char **keywords, - const char **values, +PQconnectdbParams(char const* const*keywords, + char const* const*values, int expand_dbname) { PGconn *conn = PQconnectStartParams(keywords, values, expand_dbname); @@ -381,8 +381,8 @@ PQconnectdbParams(const char **keywords, * check server status, accepting parameters identical to
PQconnectdbParams */ PGPing -PQpingParams(const char **keywords, - const char **values, +PQpingParams(char const* const*keywords, + char const* const*values, int expand_dbname) { PGconn *conn = PQconnectStartParams(keywords, values, expand_dbname); @@ -464,8 +464,8 @@ PQping(const char *conninfo) * See PQconnectPoll for more info. */ PGconn * -PQconnectStartParams(const char **keywords, - const char **values, +PQconnectStartParams(char const* const*keywords, + char const* const*values, int expand_dbname) { PGconn *conn; @@ -4249,7 +4249,7 @@ conninfo_parse(const char *conninfo, PQE * keywords will take precedence, however. */ static PQconninfoOption * -conninfo_array_parse(const char **keywords, const char **values, +conninfo_array_parse(char const* const*keywords, char const* const*values, PQExpBuffer errorMessage, bool use_defaults, int expand_dbname) {
inline patch 2: postgresql-9.1-9.1.0/src/interfaces/libpq/libpq-fe.h (+6/-6 lines) download inline-2.patch--- postgresql-9.1-9.1.0.orig/src/interfaces/libpq/libpq-fe.h +++ postgresql-9.1-9.1.0/src/interfaces/libpq/libpq-fe.h @@ -235,14 +235,14 @@ typedef struct pgresAttDesc /* make a new client connection to the backend */ /* Asynchronous (non-blocking) */ extern PGconn *PQconnectStart(const char *conninfo); -extern PGconn *PQconnectStartParams(const char **keywords, - const char **values, int expand_dbname); +extern PGconn *PQconnectStartParams(char const* const*keywords, + char const* const*values, int expand_dbname); extern PostgresPollingStatusType PQconnectPoll(PGconn *conn); /* Synchronous (blocking) */ extern PGconn *PQconnectdb(const char *conninfo); -extern PGconn *PQconnectdbParams(const char **keywords, - const char **values, int expand_dbname); +extern PGconn *PQconnectdbParams(char const* const*keywords, + char const* const*values, int expand_dbname); extern PGconn *PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, const char *pgtty, const char *dbName, @@ -413,8 +413,8 @@ extern int PQsetnonblocking(PGconn *conn extern int PQisnonblocking(const PGconn *conn); extern int PQisthreadsafe(void); extern PGPing PQping(const char *conninfo); -extern PGPing PQpingParams(const char **keywords, - const char **values, int expand_dbname); +extern PGPing PQpingParams(char const* const*keywords, + char const* const*values, int expand_dbname); /* Force the write buffer to be written (or at least try) */ extern int PQflush(PGconn *conn);
Patches: download all (2 files, .tar.gz)

view thread (7+ messages)  latest in thread

Message-ID: <201109201605.p8KG5tku049175@wwwmaster.postgresql.org>
Permalink:  ../201109201605.p8KG5tku049175@wwwmaster.postgresql.org/
Also on:    postgresql.org/message-id/201109201605.p8KG5tku049175@wwwmaster.postgresql.org

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: lionel@mamane.lu
  Subject: Re: BUG #6216: Calling PQconnectdbParams from C++ with a char**
  In-Reply-To: <201109201605.p8KG5tku049175@wwwmaster.postgresql.org>
  References: <201109201605.p8KG5tku049175@wwwmaster.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox