Re: Problems with a C function, pg_uname(), and String concatenation. - Mailing list pgsql-general

From Tom Lane
Subject Re: Problems with a C function, pg_uname(), and String concatenation.
Date
Msg-id 3265.1214921565@sss.pgh.pa.us
Whole thread Raw
In response to Problems with a C function, pg_uname(), and String concatenation.  (Rafael Martinez <r.m.guerrero@usit.uio.no>)
List pgsql-general
Rafael Martinez <r.m.guerrero@usit.uio.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

pgsql-general by date:

Previous
From: "Chandra ASGI Tech"
Date:
Subject: Re: Need some help
Next
From: Felipe de Jesús Molina Bravo
Date:
Subject: SRF written in C