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

Commit53d4f5f

Browse files
committed
Avoid memcpy() with same source and destination during relmapper init.
A narrow reading of the C standard says that memcpy(x,x,n) is undefined,although it's hard to envision an implementation that would reallymisbehave. However, analysis tools such as valgrind might whine aboutthis; accordingly, let's band-aid relmapper.c to not do it.See also5b63050,d3f4e8a,ad7b48e, and other similar fixes.Apparently, none of those folk tried valgrinding initdb? This has beenlike this for long enough that I'm surprised it hasn't been reportedbefore.Back-patch, just in case anybody wants to use a back branch on a platformthat complains about this; we back-patched those earlier fixes too.Discussion:https://postgr.es/m/161790.1608310142@sss.pgh.pa.us
1 parent2e0fedf commit53d4f5f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

‎src/backend/utils/cache/relmapper.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,8 +928,15 @@ write_relmap_file(bool shared, RelMapFile *newmap,
928928
}
929929
}
930930

931-
/* Success, update permanent copy */
932-
memcpy(realmap,newmap,sizeof(RelMapFile));
931+
/*
932+
* Success, update permanent copy. During bootstrap, we might be working
933+
* on the permanent copy itself, in which case skip the memcpy() to avoid
934+
* invoking nominally-undefined behavior.
935+
*/
936+
if (realmap!=newmap)
937+
memcpy(realmap,newmap,sizeof(RelMapFile));
938+
else
939+
Assert(!send_sinval);/* must be bootstrapping */
933940

934941
/* Critical section done */
935942
if (write_wal)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp