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

Commit1784f27

Browse files
committed
Replace remaining StrNCpy() by strlcpy()
They are equivalent, except that StrNCpy() zero-fills the entiredestination buffer instead of providing just one trailing zero. Forall but a tiny number of callers, that's just overhead rather thanbeing 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 returnvalue, 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
1 parentcec57b1 commit1784f27

File tree

20 files changed

+34
-106
lines changed

20 files changed

+34
-106
lines changed

‎contrib/pgcrypto/crypt-des.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ px_crypt_des(const char *key, const char *setting)
720720
if (des_setkey((char*)keybuf))
721721
returnNULL;
722722
}
723-
StrNCpy(output,setting,10);
723+
strlcpy(output,setting,10);
724724

725725
/*
726726
* Double check that we weren't given a short setting. If we were, the

‎src/backend/access/transam/slru.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns,
252252
*/
253253
ctl->shared=shared;
254254
ctl->do_fsync= true;/* default behavior */
255-
StrNCpy(ctl->Dir,subdir,sizeof(ctl->Dir));
255+
strlcpy(ctl->Dir,subdir,sizeof(ctl->Dir));
256256
}
257257

258258
/*

‎src/backend/access/transam/xlogarchive.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ ExecuteRecoveryCommand(const char *command, const char *commandName, bool failOn
323323
case'r':
324324
/* %r: filename of last restartpoint */
325325
sp++;
326-
StrNCpy(dp,lastRestartPointFname,endp-dp);
326+
strlcpy(dp,lastRestartPointFname,endp-dp);
327327
dp+=strlen(dp);
328328
break;
329329
case'%':

‎src/backend/catalog/pg_constraint.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ ChooseConstraintName(const char *name1, const char *name2,
484484
conDesc=table_open(ConstraintRelationId,AccessShareLock);
485485

486486
/* try the unmodified label first */
487-
StrNCpy(modlabel,label,sizeof(modlabel));
487+
strlcpy(modlabel,label,sizeof(modlabel));
488488

489489
for (;;)
490490
{

‎src/backend/commands/indexcmds.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2246,7 +2246,7 @@ ChooseRelationName(const char *name1, const char *name2,
22462246
charmodlabel[NAMEDATALEN];
22472247

22482248
/* try the unmodified label first */
2249-
StrNCpy(modlabel,label,sizeof(modlabel));
2249+
strlcpy(modlabel,label,sizeof(modlabel));
22502250

22512251
for (;;)
22522252
{

‎src/backend/commands/statscmds.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ ChooseExtendedStatisticName(const char *name1, const char *name2,
681681
charmodlabel[NAMEDATALEN];
682682

683683
/* try the unmodified label first */
684-
StrNCpy(modlabel,label,sizeof(modlabel));
684+
strlcpy(modlabel,label,sizeof(modlabel));
685685

686686
for (;;)
687687
{

‎src/backend/commands/tablecmds.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
606606
* Truncate relname to appropriate length (probably a waste of time, as
607607
* parser should have done this already).
608608
*/
609-
StrNCpy(relname, stmt->relation->relname, NAMEDATALEN);
609+
strlcpy(relname, stmt->relation->relname, NAMEDATALEN);
610610

611611
/*
612612
* Check consistency of arguments

‎src/backend/postmaster/pgstat.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4367,7 +4367,7 @@ pgstat_send_archiver(const char *xlog, bool failed)
43674367
*/
43684368
pgstat_setheader(&msg.m_hdr,PGSTAT_MTYPE_ARCHIVER);
43694369
msg.m_failed=failed;
4370-
StrNCpy(msg.m_xlog,xlog,sizeof(msg.m_xlog));
4370+
strlcpy(msg.m_xlog,xlog,sizeof(msg.m_xlog));
43714371
msg.m_timestamp=GetCurrentTimestamp();
43724372
pgstat_send(&msg,sizeof(msg));
43734373
}

‎src/backend/replication/logical/logical.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include"replication/snapbuild.h"
4040
#include"storage/proc.h"
4141
#include"storage/procarray.h"
42+
#include"utils/builtins.h"
4243
#include"utils/memutils.h"
4344

4445
/* data for errcontext callback */
@@ -288,6 +289,7 @@ CreateInitDecodingContext(const char *plugin,
288289
{
289290
TransactionIdxmin_horizon=InvalidTransactionId;
290291
ReplicationSlot*slot;
292+
NameDataplugin_name;
291293
LogicalDecodingContext*ctx;
292294
MemoryContextold_context;
293295

@@ -319,9 +321,14 @@ CreateInitDecodingContext(const char *plugin,
319321
(errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
320322
errmsg("cannot create logical replication slot in transaction that has performed writes")));
321323

322-
/* register output plugin name with slot */
324+
/*
325+
* Register output plugin name with slot. We need the mutex to avoid
326+
* concurrent reading of a partially copied string. But we don't want any
327+
* complicated code while holding a spinlock, so do namestrcpy() outside.
328+
*/
329+
namestrcpy(&plugin_name,plugin);
323330
SpinLockAcquire(&slot->mutex);
324-
StrNCpy(NameStr(slot->data.plugin),plugin,NAMEDATALEN);
331+
slot->data.plugin=plugin_name;
325332
SpinLockRelease(&slot->mutex);
326333

327334
if (XLogRecPtrIsInvalid(restart_lsn))

‎src/backend/replication/slot.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ ReplicationSlotCreate(const char *name, bool db_specific,
275275

276276
/* first initialize persistent data */
277277
memset(&slot->data,0,sizeof(ReplicationSlotPersistentData));
278-
StrNCpy(NameStr(slot->data.name),name,NAMEDATALEN);
278+
namestrcpy(&slot->data.name,name);
279279
slot->data.database=db_specific ?MyDatabaseId :InvalidOid;
280280
slot->data.persistency=persistency;
281281

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp