From 4f09b55dc3d054e019c931845e3937830cee4e19 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Thu, 12 Jul 2007 23:10:57 +0000
Subject: [PATCH] Simplify overly-cute array coding to avoid an apparent gcc
 bug, which may or may not be harmless.  Report from Stefan, patch from
 Heikki.

---
 contrib/pg_trgm/trgm_op.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/contrib/pg_trgm/trgm_op.c b/contrib/pg_trgm/trgm_op.c
index e9afef4b21f..6b0e28d5d20 100644
--- a/contrib/pg_trgm/trgm_op.c
+++ b/contrib/pg_trgm/trgm_op.c
@@ -194,19 +194,18 @@ show_trgm(PG_FUNCTION_ARGS)
 	Datum	   *d;
 	ArrayType  *a;
 	trgm	   *ptr;
+	int			i;
 
 	trg = generate_trgm(VARDATA(in), VARSIZE(in) - VARHDRSZ);
 	d = (Datum *) palloc(sizeof(Datum) * (1 + ARRNELEM(trg)));
 
-	ptr = GETARR(trg);
-	while (ptr - GETARR(trg) < ARRNELEM(trg))
+	for (i = 0, ptr = GETARR(trg); i < ARRNELEM(trg); i++, ptr++)
 	{
 		text	   *item = (text *) palloc(VARHDRSZ + 3);
 
 		SET_VARSIZE(item, VARHDRSZ + 3);
 		CPTRGM(VARDATA(item), ptr);
-		d[ptr - GETARR(trg)] = PointerGetDatum(item);
-		ptr++;
+		d[i] = PointerGetDatum(item);
 	}
 
 	a = construct_array(
@@ -218,12 +217,8 @@ show_trgm(PG_FUNCTION_ARGS)
 						'i'
 		);
 
-	ptr = GETARR(trg);
-	while (ptr - GETARR(trg) < ARRNELEM(trg))
-	{
-		pfree(DatumGetPointer(d[ptr - GETARR(trg)]));
-		ptr++;
-	}
+	for (i = 0; i < ARRNELEM(trg); i++)
+		pfree(DatumGetPointer(d[i]));
 
 	pfree(d);
 	pfree(trg);
-- 
GitLab