aboutsummaryrefslogtreecommitdiff
path: root/src/backend/replication/logical/logical.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2020-08-10 18:51:31 +0200
committerPeter Eisentraut <peter@eisentraut.org>2020-08-10 23:20:37 +0200
commit1784f278a63866cc144fcd0a2127cadba6a2b7f8 (patch)
treece0f644de0d3a89fc8b49ff67be8428731cb041b /src/backend/replication/logical/logical.c
parentcec57b1a0fbcd3833086ba686897c5883e0a2afc (diff)
downloadpostgresql-1784f278a63866cc144fcd0a2127cadba6a2b7f8.tar.gz
postgresql-1784f278a63866cc144fcd0a2127cadba6a2b7f8.zip
Replace remaining StrNCpy() by strlcpy()
They are equivalent, except that StrNCpy() zero-fills the entire destination buffer instead of providing just one trailing zero. For all but a tiny number of callers, that's just overhead rather than being desirable. Remove StrNCpy() as it is now unused. In some cases, namestrcpy() is the more appropriate function to use. While we're here, simplify the API of namestrcpy(): Remove the return value, don't check for NULL input. Nothing was using that anyway. Also, remove a few unused name-related functions. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/44f5e198-36f6-6cdb-7fa9-60e34784daae%402ndquadrant.com
Diffstat (limited to 'src/backend/replication/logical/logical.c')
-rw-r--r--src/backend/replication/logical/logical.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index f5eb6bc3aff..57c5b513ccf 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -39,6 +39,7 @@
#include "replication/snapbuild.h"
#include "storage/proc.h"
#include "storage/procarray.h"
+#include "utils/builtins.h"
#include "utils/memutils.h"
/* data for errcontext callback */
@@ -288,6 +289,7 @@ CreateInitDecodingContext(const char *plugin,
{
TransactionId xmin_horizon = InvalidTransactionId;
ReplicationSlot *slot;
+ NameData plugin_name;
LogicalDecodingContext *ctx;
MemoryContext old_context;
@@ -319,9 +321,14 @@ CreateInitDecodingContext(const char *plugin,
(errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
errmsg("cannot create logical replication slot in transaction that has performed writes")));
- /* register output plugin name with slot */
+ /*
+ * Register output plugin name with slot. We need the mutex to avoid
+ * concurrent reading of a partially copied string. But we don't want any
+ * complicated code while holding a spinlock, so do namestrcpy() outside.
+ */
+ namestrcpy(&plugin_name, plugin);
SpinLockAcquire(&slot->mutex);
- StrNCpy(NameStr(slot->data.plugin), plugin, NAMEDATALEN);
+ slot->data.plugin = plugin_name;
SpinLockRelease(&slot->mutex);
if (XLogRecPtrIsInvalid(restart_lsn))