Re: BUG #2574: C function: arg TEXT data corrupt

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #2574: C function: arg TEXT data corrupt
Дата
Msg-id 9678.1155569220@sss.pgh.pa.us
обсуждение исходный текст
Ответ на BUG #2574: C function: arg TEXT data corrupt  ("Michael Enke" <michael.enke@wincor-nixdorf.com>)
Список pgsql-bugs
"Michael Enke" <michael.enke@wincor-nixdorf.com> writes:
> I created a C function:
> extern Datum test_arg(PG_FUNCTION_ARGS);
> PG_FUNCTION_INFO_V1(test_arg);
> Datum test_arg(PG_FUNCTION_ARGS) {
>   elog(INFO, "arg: %s", VARDATA(PG_GETARG_TEXT_P(0)));
>   PG_RETURN_INT16(0);

The VARDATA of a TEXT datum is not a C string; in particular it is not
guaranteed to be null-terminated.  This is an error in your code not
a bug.

The usual way to get a C string from a TEXT datum is to call textout,
eg

    str = DatumGetCString(DirectFunctionCall1(textout, datumval));

            regards, tom lane

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Nick Morrison
Дата:
Сообщение: no native spinlock support on os x 10.4.7
Следующее
От: Tom Lane
Дата:
Сообщение: Re: no native spinlock support on os x 10.4.7