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