"Joe Conway" <joe(dot)conway(at)mail(dot)com> writes:
> optstr = PG_GETARG_TEXT_P(0);
> jpgsql = PG_GETARG_TEXT_P(1);
> conn = PQconnectdb(VARDATA(optstr));
I think you've missed the fact that a TEXT value's VARDATA is not
null-terminated. There are numerous examples of transforming a TEXT
into a C string in the backend, see for example text_cmp/varstr_cmp
in src/backend/utils/adt/varlena.c.
regards, tom lane