Re: function returning a row

From: Kjetil Haaland <kjetil(dot)haaland(at)student(dot)uib(dot)no>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Michael Fuhr <mike(at)fuhr(dot)org>, pgsql-novice(at)postgresql(dot)org
Subject: Re: function returning a row
Date: 2005-02-01 14:19:23
Message-ID: 200502011519.24336.kjetil.haaland@student.uib.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Alvaro Herrera 2005-02-01 14:24:38 Re: [NOVICE] Last ID Problem
Previous Message Schuhmacher, Bret 2005-02-01 13:36:48 Re: LC_CTYPE question