Skip to content

Commit 86f5fcf

Browse files
committed
Fix failure when uniq-ifying an array of zero elements.
Teodor Sigaev
1 parent f9b232f commit 86f5fcf

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

contrib/intarray/_int.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,8 @@ internal_size(int *a, int len)
967967
return size;
968968
}
969969

970+
#define UNIX_UNIQ(a) a = _int_unique(a)
971+
970972
/* r is sorted and size of r > 1 */
971973
static ArrayType *
972974
_int_unique(ArrayType *r)
@@ -976,6 +978,9 @@ _int_unique(ArrayType *r)
976978
*data;
977979
int num = ARRNELEMS(r);
978980

981+
if ( num<2 )
982+
return r;
983+
979984
data = tmp = dr = ARRPTR(r);
980985
while (tmp - data < num)
981986
if (*tmp != *dr)
@@ -2445,23 +2450,6 @@ if (ARRNELEMS(a) > 1) \
24452450
qsort((void*)ARRPTR(a), ARRNELEMS(a),sizeof(int4), \
24462451
(direction) ? compASC : compDESC )
24472452

2448-
#define UNIX_UNIQ(a) a = resize_intArrayType(a, unix_uniq(ARRPTR(a), ARRNELEMS(a)))
2449-
2450-
static int32
2451-
unix_uniq(int32 *array, int32 count)
2452-
{
2453-
register int32 i,
2454-
k = 0;
2455-
2456-
for (i = 1; i < count; i++)
2457-
if (array[k] != array[i])
2458-
{
2459-
k++;
2460-
if (i > k)
2461-
array[k] = array[i];
2462-
}
2463-
return (k + 1);
2464-
}
24652453

24662454
Datum
24672455
intset(PG_FUNCTION_ARGS)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy