Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5b63050

Browse files
committed
Skip memcpy(x, x) in qunique().
It has undefined behavior. Follow the precedent of commit9a9473f. No back-patch, since themaster branch alone has this function.Discussion:https://postgr.es/m/20191229070221.GA13873@gust.leadboat.com
1 parentfac1c04 commit5b63050

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

‎src/include/lib/qunique.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ qunique(void *array, size_t elements, size_t width,
3030

3131
for (i=1,j=0;i<elements;++i)
3232
{
33-
if (compare(bytes+i*width,bytes+j*width)!=0)
34-
memcpy(bytes+++j*width,bytes+i*width,width);
33+
if (compare(bytes+i*width,bytes+j*width)!=0&&
34+
++j!=i)
35+
memcpy(bytes+j*width,bytes+i*width,width);
3536
}
3637

3738
returnj+1;
@@ -55,8 +56,9 @@ qunique_arg(void *array, size_t elements, size_t width,
5556

5657
for (i=1,j=0;i<elements;++i)
5758
{
58-
if (compare(bytes+i*width,bytes+j*width,arg)!=0)
59-
memcpy(bytes+++j*width,bytes+i*width,width);
59+
if (compare(bytes+i*width,bytes+j*width,arg)!=0&&
60+
++j!=i)
61+
memcpy(bytes+j*width,bytes+i*width,width);
6062
}
6163

6264
returnj+1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp