Content-Length: 276443 | pFad | http://github.com/postgrespro/postgres_cluster/commit/722eb325b9511e9d0a8669112c636edebe2cb01b

AD Avoid memcpy() with same source and destination during relmapper init. · postgrespro/postgres_cluster@722eb32 · GitHub
Skip to content

Commit 722eb32

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 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 d28a14d commit 722eb32

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)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/postgres_cluster/commit/722eb325b9511e9d0a8669112c636edebe2cb01b

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy