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

From: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>
To: Alex Page <alex(dot)page(at)cancer(dot)org(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: C Programming with postgres.h - my function crashes the database backend
Date: 2003-12-02 18:16:13
Message-ID: 20031202181613.GF2386@dcc.uchile.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Nunca se desea ardientemente lo que solo se desea por razón" (F. Alexandre)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Randolf Richardson 2003-12-02 18:17:57 Re: Triggers, Stored Procedures, PHP. was: Re: PostgreSQL Advocacy, Thoughts and Comments
Previous Message Randolf Richardson 2003-12-02 18:05:13 Re: PostgreSQL Advocacy, Thoughts and Comments