Re: C Programming with postgres.h - my function crashes - Mailing list pgsql-general

From Jan Wieck
Subject Re: C Programming with postgres.h - my function crashes
Date
Msg-id 3FCCDFCE.8020107@Yahoo.com
Whole thread Raw
In response to Re: C Programming with postgres.h - my function crashes the database backend  (Alvaro Herrera <alvherre@dcc.uchile.cl>)
Responses Re: C Programming with postgres.h - my function crashes
List 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,
whichis 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@Yahoo.com #


pgsql-general by date:

Previous
From: Lamar Owen
Date:
Subject: Re: perl(Pg) (S)RPM
Next
From: "Keith C. Perry"
Date:
Subject: Re: pg_dump on one user not whole database