mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-02-17 19:30:00 +08:00
Skip memcpy(x, x) in qunique().
It has undefined behavior. Follow the precedent of commit
9a9473f3cc
. No back-patch, since the
master branch alone has this function.
Discussion: https://postgr.es/m/20191229070221.GA13873@gust.leadboat.com
This commit is contained in:
parent
fac1c04fec
commit
5b630501e9
@ -30,8 +30,9 @@ qunique(void *array, size_t elements, size_t width,
|
||||
|
||||
for (i = 1, j = 0; i < elements; ++i)
|
||||
{
|
||||
if (compare(bytes + i * width, bytes + j * width) != 0)
|
||||
memcpy(bytes + ++j * width, bytes + i * width, width);
|
||||
if (compare(bytes + i * width, bytes + j * width) != 0 &&
|
||||
++j != i)
|
||||
memcpy(bytes + j * width, bytes + i * width, width);
|
||||
}
|
||||
|
||||
return j + 1;
|
||||
@ -55,8 +56,9 @@ qunique_arg(void *array, size_t elements, size_t width,
|
||||
|
||||
for (i = 1, j = 0; i < elements; ++i)
|
||||
{
|
||||
if (compare(bytes + i * width, bytes + j * width, arg) != 0)
|
||||
memcpy(bytes + ++j * width, bytes + i * width, width);
|
||||
if (compare(bytes + i * width, bytes + j * width, arg) != 0 &&
|
||||
++j != i)
|
||||
memcpy(bytes + j * width, bytes + i * width, width);
|
||||
}
|
||||
|
||||
return j + 1;
|
||||
|
Loading…
Reference in New Issue
Block a user