mirror of
https://github.com/postgres/postgres.git
synced 2025-06-07 11:02:12 +03:00
Fix failure when uniq-ifying an array of zero elements.
Teodor Sigaev
This commit is contained in:
parent
bdec4179b7
commit
1e3fbccd6c
@ -969,6 +969,8 @@ internal_size(int *a, int len)
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define UNIX_UNIQ(a) a = _int_unique(a)
|
||||||
|
|
||||||
/* r is sorted and size of r > 1 */
|
/* r is sorted and size of r > 1 */
|
||||||
static ArrayType *
|
static ArrayType *
|
||||||
_int_unique(ArrayType *r)
|
_int_unique(ArrayType *r)
|
||||||
@ -978,6 +980,9 @@ _int_unique(ArrayType *r)
|
|||||||
*data;
|
*data;
|
||||||
int num = ARRNELEMS(r);
|
int num = ARRNELEMS(r);
|
||||||
|
|
||||||
|
if ( num<2 )
|
||||||
|
return r;
|
||||||
|
|
||||||
data = tmp = dr = ARRPTR(r);
|
data = tmp = dr = ARRPTR(r);
|
||||||
while (tmp - data < num)
|
while (tmp - data < num)
|
||||||
if (*tmp != *dr)
|
if (*tmp != *dr)
|
||||||
@ -2447,23 +2452,6 @@ if (ARRNELEMS(a) > 1) \
|
|||||||
qsort((void*)ARRPTR(a), ARRNELEMS(a),sizeof(int4), \
|
qsort((void*)ARRPTR(a), ARRNELEMS(a),sizeof(int4), \
|
||||||
(direction) ? compASC : compDESC )
|
(direction) ? compASC : compDESC )
|
||||||
|
|
||||||
#define UNIX_UNIQ(a) a = resize_intArrayType(a, unix_uniq(ARRPTR(a), ARRNELEMS(a)))
|
|
||||||
|
|
||||||
static int32
|
|
||||||
unix_uniq(int32 *array, int32 count)
|
|
||||||
{
|
|
||||||
register int32 i,
|
|
||||||
k = 0;
|
|
||||||
|
|
||||||
for (i = 1; i < count; i++)
|
|
||||||
if (array[k] != array[i])
|
|
||||||
{
|
|
||||||
k++;
|
|
||||||
if (i > k)
|
|
||||||
array[k] = array[i];
|
|
||||||
}
|
|
||||||
return (k + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Datum
|
Datum
|
||||||
intset(PG_FUNCTION_ARGS)
|
intset(PG_FUNCTION_ARGS)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user