bug in gist hstore?

Поиск
Список
Период
Сортировка
Искать

bug in gist hstore?

От:
Gregory Stark <stark@enterprisedb.com>
Дата:

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

Re: bug in gist hstore?

От:
Gregory Stark <stark@enterprisedb.com>
Дата:

"Gregory Stark"  writes:

> In the following code from hstore_io.c, is HStore a varlena? 

Sorry, thinko, it is a varlena but "size" isn't the first struct field,
there's a "len" field first.

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

FAQ