Skip site navigation (1) Skip section navigation (2)

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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Michael Enke" <michael(dot)enke(at)wincor-nixdorf(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2574: C function: arg TEXT data corrupt
Date: 2006-08-14 15:27:00
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-bugspgsql-general
"Michael Enke" <michael(dot)enke(at)wincor-nixdorf(dot)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,

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

			regards, tom lane

In response to


pgsql-bugs by date

Next:From: Tom LaneDate: 2006-08-14 15:29:32
Subject: Re: no native spinlock support on os x 10.4.7
Previous:From: Michael EnkeDate: 2006-08-14 13:53:34
Subject: BUG #2574: C function: arg TEXT data corrupt

pgsql-general by date

Next:From: Michael FuhrDate: 2006-08-14 15:29:48
Subject: Re: prepared statement already exists
Previous:From: AgentMDate: 2006-08-14 15:14:36
Subject: Re: Best approach for a "gap-less" sequence

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group