pgsql-bugs(at)postgresql(dot)org writes:
> text *pattern = (text*)PG_GETARG_TEXT_P(0);
> text *sample = (text*)PG_GETARG_TEXT_P(1);
> char *char_pattern = (char*)VARDATA(pattern);
> char *char_sample = (char*)VARDATA(sample);
You can't convert text* to char* with just a cast. The result won't
(usually) be null-terminated where it should be; so you end up with
strings that have garbage on the end. Use textout() like all the
existing code does when it wants a null-terminated string.
regards, tom lane