Re: libpq: PQcmdStatus, PQcmdTuples signatures can be painlessly improved

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Alex Goncharov <alex-goncharov(at)comcast(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: libpq: PQcmdStatus, PQcmdTuples signatures can be painlessly improved
Date: 2012-01-10 17:13:42
Message-ID: 1326215622.22414.2.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On tis, 2011-12-13 at 07:55 -0500, Alex Goncharov wrote:
> char *PQcmdStatus(PGresult *res);
> char *PQcmdTuples(PGresult *res);
>
> Unreasonable:
>
> a. What, these two can modify 'res' I pass in?..
>
> b. Oh, yes, because they return 'char *' pointing to
> 'res->cmdStatus+n', so, a libpq user may write:
>
> char *s = PQcmdStatus(res);
> *s = 'x';
>
> and have 'res' modified. (Would be the user's fault, of course.)
>
Note that const PGresult * would only warn against changing the fields
of the PGresult struct. It doesn't do anything about changing the data
pointed to by pointers in the PGresult struct. So what you are saying
doesn't follow.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2012-01-10 17:29:01 Re: Add SPI results constants available for PL/*
Previous Message Tom Lane 2012-01-10 16:55:50 Re: Sending notifications from the master to the standby