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

Appearance settings

Commit 4878674

Browse filesBrowse 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 really misbehave. However, analysis tools such as valgrind might whine about this; accordingly, let's band-aid relmapper.c to not do it. See also 5b63050, d3f4e8a, ad7b48e, and other similar fixes. Apparently, none of those folk tried valgrinding initdb? This has been like this for long enough that I'm surprised it hasn't been reported before. Back-patch, just in case anybody wants to use a back branch on a platform that complains about this; we back-patched those earlier fixes too. Discussion: https://postgr.es/m/161790.1608310142@sss.pgh.pa.us
1 parent b5eb07e commit 4878674
Copy full SHA for 4878674

File tree

Expand file treeCollapse file tree

1 file changed

+9
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/backend/utils/cache/relmapper.c
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,8 +839,15 @@ write_relmap_file(bool shared, RelMapFile *newmap,
839839
}
840840
}
841841

842-
/* Success, update permanent copy */
843-
memcpy(realmap, newmap, sizeof(RelMapFile));
842+
/*
843+
* Success, update permanent copy. During bootstrap, we might be working
844+
* on the permanent copy itself, in which case skip the memcpy() to avoid
845+
* invoking nominally-undefined behavior.
846+
*/
847+
if (realmap != newmap)
848+
memcpy(realmap, newmap, sizeof(RelMapFile));
849+
else
850+
Assert(!send_sinval); /* must be bootstrapping */
844851

845852
/* Critical section done */
846853
if (write_wal)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.