Kjetil Haaland <kjetil.haaland@student.uib.no> writes:
> 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);
> snprintf (in, VARSIZE(intext) - VARHDRSZ + 1, VARDATA(intext));
> snprintf (sml, VARSIZE(smltext) - VARHDRSZ + 1, VARDATA(smltext));
I'm not sure what you think the above snprintf's are going to do, but
it seems certain to be bad. The "format string" you are passing is
neither null-terminated nor guaranteed to be free of %'s.
memcpy would be safer; and of course you need to explicitly append a
null byte afterwards.
regards, tom lane