Re: C Programming with postgres.h - my function crashes

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>
Cc: Alex Page <alex(dot)page(at)cancer(dot)org(dot)uk>, pgsql-general(at)postgresql(dot)org
Subject: Re: C Programming with postgres.h - my function crashes
Date: 2003-12-02 18:54:06
Message-ID: 3FCCDFCE.8020107@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alvaro Herrera wrote:

> On Tue, Dec 02, 2003 at 05:56:45PM +0000, Alex Page wrote:
>
>> Datum enum_gender_in(PG_FUNCTION_ARGS) {
>> text *invalue = PG_GETARG_TEXT_P(0);
>>
>> if ( strcmp ( VARDATA(invalue), "Male" ) ) { /* VARDATA gets the data portion of a "varlena" struct, which is typedef'd to "text" */
>> PG_RETURN_INT32( 0 );
>> }
>> PG_RETURN_INT32( 1 );
>> }
>
> VARDATA is not 0-terminated, so you can't use strcmp on it. Maybe you
> should use memcmp instead.
>

First of all, the argument to a type input procedure is a nul terminated
CString, not text.

Alex, why don't you look at an existing datatype in backend/utils/adt?

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Keith C. Perry 2003-12-02 18:55:54 Re: pg_dump on one user not whole database
Previous Message Lamar Owen 2003-12-02 18:48:14 Re: perl(Pg) (S)RPM