Re: Problems with a C function, pg_uname(), and String concatenation.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Rafael Martinez <r(dot)m(dot)guerrero(at)usit(dot)uio(dot)no>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Problems with a C function, pg_uname(), and String concatenation.
Date: 2008-07-01 14:12:45
Message-ID: 3265.1214921565@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Rafael Martinez <r(dot)m(dot)guerrero(at)usit(dot)uio(dot)no> writes:
> We have a function in C which is accessed via a view and which produces
> a strange result when used together with || (String concatenation).
> I can not find the problem. Any C/postgres guru with any idea of how to
> fix it?

You need to set the size of the text result correctly. As is, you're
returning a 252-byte result containing embedded nulls and random
garbage. Embedded nulls, in particular, are verboten.

The fixed-size palloc is okay (as long as you're sure it's enough),
but the length word should only count valid data.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Felipe de Jesús Molina Bravo 2008-07-01 15:02:39 SRF written in C
Previous Message Chandra ASGI Tech 2008-07-01 12:56:36 Re: Need some help