From: | Gregory Stark <stark(at)enterprisedb(dot)com> |
---|---|
To: | PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | bug in gist hstore? |
Date: | 2007-02-27 17:17:16 |
Message-ID: | 877iu3h65f.fsf@stark.xeocode.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | Postg무지개 토토SQL |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Treat | 2007-02-27 17:21:34 | Re: Seeking Google SoC Mentors |
Previous Message | Tom Lane | 2007-02-27 17:16:28 | Re: 7.x horology regression test on Solaris buildfarm machines |