bug in gist hstore? - Mailing list pgsql-hackers

From Gregory Stark
Subject bug in gist hstore?
Date
Msg-id 877iu3h65f.fsf@stark.xeocode.com
Whole thread Raw
Responses Re: bug in gist hstore?  (Gregory Stark <stark@enterprisedb.com>)
List pgsql-hackers
In the following code from hstore_io.c, is HStore a varlena? In which case is
the following code buggy because it omits to subtract VARHDRSZ from in->size
and therefore is not handling the empty hstore and also starting the loop from
the varlena header instead of the first data byte?

Or if HStore is not a varlena then PG_GETARG_HS is buggy since it calls
PG_DETOAST_DATUM() on the argument.



PG_FUNCTION_INFO_V1(hstore_out);
Datum        hstore_out(PG_FUNCTION_ARGS);
Datum
hstore_out(PG_FUNCTION_ARGS)
{HStore       *in = PG_GETARG_HS(0);int            buflen,            i;char       *out,           *ptr;char
*base= STRPTR(in);HEntry       *entries = ARRPTR(in);
 
if (in->size == 0){    out = palloc(1);    *out = '\0';    PG_FREE_IF_COPY(in, 0);    PG_RETURN_CSTRING(out);}
buflen = (4 /* " */ + 2 /* => */ + 2 /* , */ ) * in->size +    2 /* esc */ * (in->len - CALCDATASIZE(in->size, 0));
out = ptr = palloc(buflen);for (i = 0; i < in->size; i++){    *ptr++ = '"';    ptr = cpw(ptr, base + entries[i].pos,
entries[i].keylen);   *ptr++ = '"';    *ptr++ = '=';    *ptr++ = '>';
 


--  Gregory Stark EnterpriseDB          http://www.enterprisedb.com


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: 7.x horology regression test on Solaris buildfarm machines
Next
From: Josh Berkus
Date:
Subject: Re: Seeking Google SoC Mentors