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

Commit51f62d5

Browse files
committed
Standardize on MAXPGPATH as the size of a file pathname buffer,
eliminating some wildly inconsistent coding in various parts of thesystem. I set MAXPGPATH = 1024 in config.h.in. If anyone is reallyconvinced that there ought to be a configure-time test to set thevalue, go right ahead ... but I think it's a waste of time.
1 parent8a17ed6 commit51f62d5

File tree

22 files changed

+183
-193
lines changed

22 files changed

+183
-193
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.6 1999/10/24 20:42:27 tgl Exp $
8+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.7 1999/10/25 03:07:42 tgl Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -33,8 +33,8 @@ voidStartupXLOG(void);
3333
voidShutdownXLOG(void);
3434
voidCreateCheckPoint(boolshutdown);
3535

36-
charXLogDir[MAXPGPATH+1];
37-
charControlFilePath[MAXPGPATH+1];
36+
charXLogDir[MAXPGPATH];
37+
charControlFilePath[MAXPGPATH];
3838
uint32XLOGbuffers=0;
3939
XLogRecPtrMyLastRecPtr= {0,0};
4040
boolStopIfError= false;
@@ -147,8 +147,8 @@ typedef struct CheckPoint
147147
#defineXLogFileSize(XLogLastSeg * XLogSegSize)
148148

149149
#defineXLogFileName(path,log,seg)\
150-
sprintf(path,"%.*s%c%08X%08X",\
151-
MAXPGPATH, XLogDir, SEP_CHAR, log, seg)
150+
snprintf(path,MAXPGPATH, "%s%c%08X%08X",\
151+
XLogDir, SEP_CHAR, log, seg)
152152

153153
#definePrevBufIdx(curridx)\
154154
((curridx == 0) ? XLogCtl->XLogCacheBlck : (curridx - 1))
@@ -718,7 +718,7 @@ XLogWrite(char *buffer)
718718
staticint
719719
XLogFileInit(uint32log,uint32seg)
720720
{
721-
charpath[MAXPGPATH+1];
721+
charpath[MAXPGPATH];
722722
intfd;
723723

724724
XLogFileName(path,log,seg);
@@ -760,7 +760,7 @@ XLogFileInit(uint32 log, uint32 seg)
760760
staticint
761761
XLogFileOpen(uint32log,uint32seg,boolecont)
762762
{
763-
charpath[MAXPGPATH+1];
763+
charpath[MAXPGPATH];
764764
intfd;
765765

766766
XLogFileName(path,log,seg);
@@ -1067,7 +1067,7 @@ next_record_is_invalid:;
10671067
readId++;
10681068
}
10691069
{
1070-
charpath[MAXPGPATH+1];
1070+
charpath[MAXPGPATH];
10711071

10721072
XLogFileName(path,readId,readSeg);
10731073
unlink(path);

‎src/backend/bootstrap/bootstrap.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.69 1999/10/06 21:58:02 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.70 1999/10/25 03:07:43 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -333,8 +333,10 @@ BootstrapMain(int argc, char *argv[])
333333
*/
334334
if (IsUnderPostmaster||xloginit)
335335
{
336-
sprintf(XLogDir,"%s%cpg_xlog",DataDir,SEP_CHAR);
337-
sprintf(ControlFilePath,"%s%cpg_control",DataDir,SEP_CHAR);
336+
snprintf(XLogDir,MAXPGPATH,"%s%cpg_xlog",
337+
DataDir,SEP_CHAR);
338+
snprintf(ControlFilePath,MAXPGPATH,"%s%cpg_control",
339+
DataDir,SEP_CHAR);
338340
}
339341

340342
if (IsUnderPostmaster&&xloginit)

‎src/backend/commands/dbcommands.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.41 1999/09/24 00:24:17 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.42 1999/10/25 03:07:43 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -38,9 +38,9 @@ createdb(char *dbname, char *dbpath, int encoding, CommandDest dest)
3838
{
3939
Oiddb_id;
4040
int4user_id;
41-
charbuf[512];
41+
charbuf[MAXPGPATH+100];
4242
char*lp,
43-
loc[512];
43+
loc[MAXPGPATH];
4444

4545
/*
4646
* If this call returns, the database does not exist and we're allowed
@@ -56,7 +56,7 @@ createdb(char *dbname, char *dbpath, int encoding, CommandDest dest)
5656
{
5757
if (*(dbpath+strlen(dbpath)-1)==SEP_CHAR)
5858
*(dbpath+strlen(dbpath)-1)='\0';
59-
snprintf(loc,512,"%s%c%s",dbpath,SEP_CHAR,dbname);
59+
snprintf(loc,sizeof(loc),"%s%c%s",dbpath,SEP_CHAR,dbname);
6060
}
6161
else
6262
strcpy(loc,dbname);
@@ -71,11 +71,11 @@ createdb(char *dbname, char *dbpath, int encoding, CommandDest dest)
7171
if (mkdir(lp,S_IRWXU)!=0)
7272
elog(ERROR,"Unable to create database directory '%s'",lp);
7373

74-
snprintf(buf,512,"%s %s%cbase%ctemplate1%c*%s",
74+
snprintf(buf,sizeof(buf),"%s %s%cbase%ctemplate1%c*'%s'",
7575
COPY_CMD,DataDir,SEP_CHAR,SEP_CHAR,SEP_CHAR,lp);
7676
system(buf);
7777

78-
snprintf(buf,512,
78+
snprintf(buf,sizeof(buf),
7979
"insert into pg_database (datname, datdba, encoding, datpath)"
8080
" values ('%s', '%d', '%d', '%s');",dbname,user_id,encoding,
8181
loc);
@@ -89,8 +89,8 @@ destroydb(char *dbname, CommandDest dest)
8989
int4user_id;
9090
Oiddb_id;
9191
char*path,
92-
dbpath[MAXPGPATH+1],
93-
buf[MAXPGPATH+50];
92+
dbpath[MAXPGPATH],
93+
buf[MAXPGPATH+100];
9494
Relationpgdbrel;
9595
HeapScanDescpgdbscan;
9696
ScanKeyDatakey;
@@ -233,7 +233,7 @@ check_permissions(char *command,
233233
booluse_super;
234234
char*userName;
235235
text*dbtext;
236-
charpath[MAXPGPATH+1];
236+
charpath[MAXPGPATH];
237237

238238
userName=GetPgUserName();
239239
utup=SearchSysCacheTuple(USENAME,
@@ -332,7 +332,7 @@ static void
332332
stop_vacuum(char*dbpath,char*dbname)
333333
{
334334
#ifdefNOT_USED
335-
charfilename[MAXPGPATH+1];
335+
charfilename[MAXPGPATH];
336336
FILE*fp;
337337
intpid;
338338

‎src/backend/libpq/pqcomm.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*
2929
* Copyright (c) 1994, Regents of the University of California
3030
*
31-
*$Id: pqcomm.c,v 1.85 1999/10/23 03:13:22 tgl Exp $
31+
*$Id: pqcomm.c,v 1.86 1999/10/25 03:07:44 tgl Exp $
3232
*
3333
*-------------------------------------------------------------------------
3434
*/
@@ -155,7 +155,8 @@ pq_close(void)
155155
*Stream functions are used for vanilla TCP connection protocol.
156156
*/
157157

158-
staticcharsock_path[MAXPGPATH+1]="";
158+
staticcharsock_path[MAXPGPATH];
159+
159160

160161
/* StreamDoUnlink()
161162
* Shutdown routine for backend connection

‎src/backend/postmaster/postmaster.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.126 1999/10/08 05:36:58 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.127 1999/10/25 03:07:45 tgl Exp $
1414
*
1515
* NOTES
1616
*
@@ -179,7 +179,7 @@ static time_ttnow;
179179
/*
180180
* Default Values
181181
*/
182-
staticcharExecfile[MAXPATHLEN]="";
182+
staticcharExecfile[MAXPGPATH];
183183

184184
staticintServerSock_INET=INVALID_SOCK;/* stream socket server */
185185

@@ -195,7 +195,7 @@ static SSL_CTX *SSL_context = NULL; /* Global SSL context */
195195
/*
196196
* Set by the -o option
197197
*/
198-
staticcharExtraOptions[MAXPATHLEN]="";
198+
staticcharExtraOptions[MAXPGPATH];
199199

200200
/*
201201
* These globals control the behavior of the postmaster in case some
@@ -294,10 +294,10 @@ checkDataDir(const char *DataDir, bool *DataDirOK)
294294
}
295295
else
296296
{
297-
charpath[MAXPATHLEN];
297+
charpath[MAXPGPATH];
298298
FILE*fp;
299299

300-
sprintf(path,"%s%cbase%ctemplate1%cpg_class",
300+
snprintf(path,sizeof(path),"%s%cbase%ctemplate1%cpg_class",
301301
DataDir,SEP_CHAR,SEP_CHAR,SEP_CHAR);
302302
#ifndef__CYGWIN32__
303303
fp=AllocateFile(path,"r");
@@ -446,7 +446,7 @@ PostmasterMain(int argc, char *argv[])
446446
case'b':
447447
/* Set the backend executable file to use. */
448448
if (!ValidateBinary(optarg))
449-
strcpy(Execfile,optarg);
449+
StrNCpy(Execfile,optarg,MAXPGPATH);
450450
else
451451
{
452452
fprintf(stderr,"%s: invalid backend \"%s\"\n",
@@ -1698,7 +1698,7 @@ DoBackend(Port *port)
16981698
{
16991699
char*av[ARGV_SIZE*2];
17001700
intac=0;
1701-
charexecbuf[MAXPATHLEN];
1701+
charexecbuf[MAXPGPATH];
17021702
chardebugbuf[ARGV_SIZE];
17031703
charprotobuf[ARGV_SIZE];
17041704
chardbbuf[ARGV_SIZE];
@@ -1749,7 +1749,7 @@ DoBackend(Port *port)
17491749
* ----------------
17501750
*/
17511751

1752-
StrNCpy(execbuf,Execfile,MAXPATHLEN);
1752+
StrNCpy(execbuf,Execfile,MAXPGPATH);
17531753
av[ac++]=execbuf;
17541754

17551755
/*
@@ -2013,7 +2013,7 @@ SSDataBase(bool startup)
20132013
{
20142014
char*av[ARGV_SIZE*2];
20152015
intac=0;
2016-
charexecbuf[MAXPATHLEN];
2016+
charexecbuf[MAXPGPATH];
20172017
charnbbuf[ARGV_SIZE];
20182018
chardbbuf[ARGV_SIZE];
20192019

@@ -2024,7 +2024,7 @@ SSDataBase(bool startup)
20242024
StreamClose(ServerSock_UNIX);
20252025
#endif
20262026

2027-
StrNCpy(execbuf,Execfile,MAXPATHLEN);
2027+
StrNCpy(execbuf,Execfile,MAXPGPATH);
20282028
av[ac++]=execbuf;
20292029

20302030
av[ac++]="-d";

‎src/backend/storage/smgr/md.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.56 1999/10/06 06:38:04 inoue Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.57 1999/10/25 03:07:47 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -591,7 +591,7 @@ mdblindwrt(char *dbstr,
591591
else
592592
/* this is work arround only !!! */
593593
{
594-
chardbpath[MAXPGPATH+1];
594+
chardbpath[MAXPGPATH];
595595
Oidid;
596596
char*tmpPath;
597597

@@ -628,7 +628,7 @@ mdblindwrt(char *dbstr,
628628
else
629629
/* this is work arround only !!! */
630630
{
631-
chardbpath[MAXPGPATH+1];
631+
chardbpath[MAXPGPATH];
632632
Oidid;
633633
char*tmpPath;
634634

‎src/backend/tcop/postgres.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.135 1999/10/23 03:13:22 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.136 1999/10/25 03:07:48 tgl Exp $
1111
*
1212
* NOTES
1313
* this is the "main" module of the postgres backend and
@@ -92,7 +92,6 @@
9292
* ----------------
9393
*/
9494

95-
/*static boolEnableRewrite = true; , never changes why have it*/
9695
CommandDestwhereToSendOutput=Debug;
9796

9897
/* Define status buffer needed by PS_SET_STATUS */
@@ -114,8 +113,6 @@ intdontExecute = 0;
114113
staticintShowStats;
115114
staticboolIsEmptyQuery= false;
116115

117-
charrelname[80];/* current relation name */
118-
119116
/* note: these declarations had better match tcopprot.h */
120117
DLLIMPORTsigjmp_bufWarn_restart;
121118

@@ -126,7 +123,7 @@ extern intNBuffers;
126123

127124
staticboolEchoQuery= false;/* default don't echo */
128125
time_ttim;
129-
charpg_pathname[256];
126+
charpg_pathname[MAXPGPATH];
130127
FILE*StatFp;
131128

132129
/* ----------------
@@ -1359,8 +1356,10 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
13591356
proc_exit(1);
13601357
}
13611358
BaseInit();
1362-
sprintf(XLogDir,"%s%cpg_xlog",DataDir,SEP_CHAR);
1363-
sprintf(ControlFilePath,"%s%cpg_control",DataDir,SEP_CHAR);
1359+
snprintf(XLogDir,MAXPGPATH,"%s%cpg_xlog",
1360+
DataDir,SEP_CHAR);
1361+
snprintf(ControlFilePath,MAXPGPATH,"%s%cpg_control",
1362+
DataDir,SEP_CHAR);
13641363
StartupXLOG();
13651364
}
13661365

@@ -1372,6 +1371,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
13721371
SetCharSet();
13731372
#endif
13741373

1374+
/* On some systems our dynloader code needs the executable's pathname */
13751375
if (FindExec(pg_pathname,argv[0],"postgres")<0)
13761376
elog(FATAL,"%s: could not locate executable, bailing out...",
13771377
argv[0]);
@@ -1494,7 +1494,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
14941494
if (!IsUnderPostmaster)
14951495
{
14961496
puts("\nPOSTGRES backend interactive interface ");
1497-
puts("$Revision: 1.135 $ $Date: 1999/10/23 03:13:22 $\n");
1497+
puts("$Revision: 1.136 $ $Date: 1999/10/25 03:07:48 $\n");
14981498
}
14991499

15001500
/*

‎src/backend/utils/adt/filename.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/filename.c,v 1.22 1999/07/17 20:17:55 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/filename.c,v 1.23 1999/10/25 03:07:49 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -31,7 +31,7 @@ filename_in(char *file)
3131
* (shexpand)
3232
*/
3333

34-
str= (char*)palloc(MAXPATHLEN*sizeof(*str));
34+
str= (char*)palloc(MAXPGPATH);
3535
str[0]='\0';
3636
if (file[0]=='~')
3737
{

‎src/backend/utils/error/elog.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.49 1999/10/06 21:58:09 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.50 1999/10/25 03:07:50 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -415,7 +415,6 @@ DebugFileOpen(void)
415415

416416
if (OutputFileName[0])
417417
{
418-
OutputFileName[MAXPGPATH-1]='\0';
419418
if ((fd=open(OutputFileName,O_CREAT |O_APPEND |O_WRONLY,
420419
0666))<0)
421420
elog(FATAL,"DebugFileOpen: open of %s: %m",
@@ -448,7 +447,8 @@ DebugFileOpen(void)
448447
fd=fileno(stderr);
449448
if (fcntl(fd,F_GETFD,0)<0)
450449
{
451-
sprintf(OutputFileName,"%s/pg.errors.%d",DataDir, (int)MyProcPid);
450+
snprintf(OutputFileName,MAXPGPATH,"%s%cpg.errors.%d",
451+
DataDir,SEP_CHAR, (int)MyProcPid);
452452
fd=open(OutputFileName,O_CREAT |O_APPEND |O_WRONLY,0666);
453453
}
454454
if (fd<0)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp