Commit 4f09b55d authored by Tom Lane's avatar Tom Lane

Simplify overly-cute array coding to avoid an apparent gcc bug, which

may or may not be harmless.  Report from Stefan, patch from Heikki.
parent 4bbb7f94
...@@ -194,19 +194,18 @@ show_trgm(PG_FUNCTION_ARGS) ...@@ -194,19 +194,18 @@ show_trgm(PG_FUNCTION_ARGS)
Datum *d; Datum *d;
ArrayType *a; ArrayType *a;
trgm *ptr; trgm *ptr;
int i;
trg = generate_trgm(VARDATA(in), VARSIZE(in) - VARHDRSZ); trg = generate_trgm(VARDATA(in), VARSIZE(in) - VARHDRSZ);
d = (Datum *) palloc(sizeof(Datum) * (1 + ARRNELEM(trg))); d = (Datum *) palloc(sizeof(Datum) * (1 + ARRNELEM(trg)));
ptr = GETARR(trg); for (i = 0, ptr = GETARR(trg); i < ARRNELEM(trg); i++, ptr++)
while (ptr - GETARR(trg) < ARRNELEM(trg))
{ {
text *item = (text *) palloc(VARHDRSZ + 3); text *item = (text *) palloc(VARHDRSZ + 3);
SET_VARSIZE(item, VARHDRSZ + 3); SET_VARSIZE(item, VARHDRSZ + 3);
CPTRGM(VARDATA(item), ptr); CPTRGM(VARDATA(item), ptr);
d[ptr - GETARR(trg)] = PointerGetDatum(item); d[i] = PointerGetDatum(item);
ptr++;
} }
a = construct_array( a = construct_array(
...@@ -218,12 +217,8 @@ show_trgm(PG_FUNCTION_ARGS) ...@@ -218,12 +217,8 @@ show_trgm(PG_FUNCTION_ARGS)
'i' 'i'
); );
ptr = GETARR(trg); for (i = 0; i < ARRNELEM(trg); i++)
while (ptr - GETARR(trg) < ARRNELEM(trg)) pfree(DatumGetPointer(d[i]));
{
pfree(DatumGetPointer(d[ptr - GETARR(trg)]));
ptr++;
}
pfree(d); pfree(d);
pfree(trg); pfree(trg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment