Re: C function woes - Mailing list pgsql-general

From Tom Lane
Subject Re: C function woes
Date
Msg-id 6973.982709790@sss.pgh.pa.us
Whole thread Raw
In response to Re: C function woes  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
I wrote:
> text *
> hello()
>  {
>         char data[] = "hello world";
>         int32 new_text_size = VARHDRSZ + sizeof(data);
>         text *new_text = (text *) palloc(new_text_size);
>
>         VARSIZE(new_text) = new_text_size;
>         memcpy(VARDATA(new_text), data, sizeof(data));
>         return new_text;
>  }

Drat.  Replace sizeof(data) by strlen(data) both places, and
*then* it's right.  You don't want the trailing null in the
TEXT object.

            regards, tom lane

pgsql-general by date:

Previous
From: Marko Kreen
Date:
Subject: Re: C function woes (more info)
Next
From: "Roderick A. Anderson"
Date:
Subject: Re: Re: Printing PostgreSQL reports