Re: Alter strings that don't belong to the application

Lists: pgsql-hackers
From: Dennis Björklund <db(at)zigo(dot)dhs(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Alter strings that don't belong to the application
Date: 2003-06-12 06:53:41
Message-ID: Pine.LNX.4.44.0306120836150.13332-100000@zigo.dhs.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I've been looking into the code of psql to fix a problem with charsets and
noticed that psql changes the strings it gets back from functions like
PQfname() and PQgetvalue().

I can't find in the docs anything that says that it is okay to alter the
returned string. It works since it's allocated and stored in the PGresult
(I assume), so it's local to one result. But it's not obvious to me just
looking at the API that it's allowed.

Or should I read that the return value is "char *" and not "const char *"
as it's okay to alter it?

--
/Dennis


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dennis Björklund <db(at)zigo(dot)dhs(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Alter strings that don't belong to the application
Date: 2003-06-12 13:29:33
Message-ID: 29261.1055424573@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

=?ISO-8859-1?Q?Dennis_Bj=F6rklund?= <db(at)zigo(dot)dhs(dot)org> writes:
> I've been looking into the code of psql to fix a problem with charsets and
> noticed that psql changes the strings it gets back from functions like
> PQfname() and PQgetvalue().

I'd call that a bug in psql. Where do you see it happening exactly?

> Or should I read that the return value is "char *" and not "const char *"
> as it's okay to alter it?

No, I think the return value ought to be treated as const char *.
We're hesitant to actually declare it that way because we'd cause compile
errors in many client applications that aren't being const-paranoid.
But the app has no business modifying those values.

regards, tom lane


From: Dennis Björklund <db(at)zigo(dot)dhs(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Alter strings that don't belong to the application
Date: 2003-06-12 14:15:29
Message-ID: Pine.LNX.4.44.0306121605520.13332-100000@zigo.dhs.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 12 Jun 2003, Tom Lane wrote:

> I'd call that a bug in psql. Where do you see it happening exactly?

It's the utf-8 validation function (mbvalidate) that removes characters
that it does not understand.

> No, I think the return value ought to be treated as const char *.
> We're hesitant to actually declare it that way because we'd cause compile
> errors in many client applications that aren't being const-paranoid.

An easy solution is to add the const as a macro that can be turned off by
those apps.

ps. I'm being blacklisted by your email server. The reason I get back is
that my letter come from a telia IP-number. Telia is the major ISP in
Sweden with something like 80-90% of the market. I actually don't belong
to those since I use another ISP (bostream), but I guess they got their
adresses from telia or something. Well, not really a problem. I send
everything to the list anyway.

--
/Dennis


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dennis Björklund <db(at)zigo(dot)dhs(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Alter strings that don't belong to the application
Date: 2003-06-12 16:18:03
Message-ID: 11076.1055434683@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

=?ISO-8859-1?Q?Dennis_Bj=F6rklund?= <db(at)zigo(dot)dhs(dot)org> writes:
> On Thu, 12 Jun 2003, Tom Lane wrote:
>> I'd call that a bug in psql. Where do you see it happening exactly?

> It's the utf-8 validation function (mbvalidate) that removes characters
> that it does not understand.

I think the string ought to be copied first ... although that might
create memory-leak problems. Could you take a look at fixing this,
while you're in the area?

> ps. I'm being blacklisted by your email server.

I can whitelist you if you have a stable IP address --- is that a static
or dynamic assignment?

regards, tom lane


From: Dennis Björklund <db(at)zigo(dot)dhs(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Alter strings that don't belong to the application
Date: 2003-06-12 16:33:57
Message-ID: Pine.LNX.4.44.0306121833040.13332-100000@zigo.dhs.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 12 Jun 2003, Tom Lane wrote:

> I think the string ought to be copied first ... although that might
> create memory-leak problems. Could you take a look at fixing this,
> while you're in the area?

Sure.

> I can whitelist you if you have a stable IP address --- is that a static
> or dynamic assignment?

It's static and I've had it for years.

--
/Dennis