Re: function returning a row - Mailing list pgsql-novice

From Kjetil Haaland
Subject Re: function returning a row
Date
Msg-id 200502011519.24336.kjetil.haaland@student.uib.no
Whole thread Raw
In response to Re: function returning a row  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: function returning a row
List pgsql-novice
On Monday 31 January 2005 18:23, Tom Lane wrote:
> memcpy would be safer; and of course you need to explicitly append a
> null byte afterwards.

Hi again

I have now used memcopy instead since that is safer and it looks like this

text *intext = PG_GETARG_TEXT_P(0);
    text *smltext = PG_GETARG_TEXT_P(1);
    in = (char*)palloc(VARSIZE(intext)-VARHDRSZ+1);
    sml = (char*)palloc(VARSIZE(smltext)-VARHDRSZ+1);

    memcpy(in, VARDATA(intext), VARSIZE(intext)-VARHDRSZ);
    in[VARSIZE(intext)-VARHDRSZ] = '\0';
    memcpy(sml, VARDATA(smltext), VARSIZE(smltext)-VARHDRSZ);
    sml[VARSIZE(smltext)-VARHDRSZ] = '\0';

    set = (set_data *) palloc(sizeof(*set)+strlen(in)+strlen(sml)+1);

I have also added a char table to the structure, so I can keep the input
strings here. That is why the palloc is changed. But I still have the same
problems with it as before. Is there anything wrong in the way I have used
the API for set returning functions? I think i have saved all the values that
I need for the next round now, so I can't find whats wrong with it.

-Kjetil

pgsql-novice by date:

Previous
From: "Schuhmacher, Bret"
Date:
Subject: Re: LC_CTYPE question
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] Last ID Problem