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

Commitdf1468e

Browse files
committed
Many more cleanups...
1 parent7c3b7d2 commitdf1468e

File tree

16 files changed

+276
-332
lines changed

16 files changed

+276
-332
lines changed

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
*
9-
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/xid.c,v 1.19 1998/12/14 05:18:33 scrappy Exp $
8+
* $Id: xid.c,v 1.20 1998/12/14 06:50:17 scrappy Exp $
119
*
1210
* OLD COMMENTS
1311
* XXX WARNING
@@ -41,13 +39,10 @@ xidin(char *representation)
4139
char*
4240
xidout(TransactionIdtransactionId)
4341
{
44-
/* return(TransactionIdFormString(transactionId)); */
45-
char*representation;
46-
4742
/* maximum 32 bit unsigned integer representation takes 10 chars */
48-
representation=palloc(11);
43+
char*representation=palloc(11);
4944

50-
sprintf(representation,"%u",transactionId);
45+
snprintf(representation,11,"%u",transactionId);
5146

5247
returnrepresentation;
5348

‎src/backend/commands/_deadcode/version.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
*The version stuff has not been tested under postgres95 and probablydoesn't
9-
*work! - jolly 8/19/95
8+
*The version stuff has not been tested under postgres95 and probably
9+
*doesn'twork! - jolly 8/19/95
1010
*
1111
*
12-
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/commands/_deadcode/Attic/version.c,v 1.16 1998/12/14 05:18:44 scrappy Exp $
12+
* $Id: version.c,v 1.17 1998/12/14 06:50:19 scrappy Exp $
1413
*
1514
* NOTES
16-
*At the point the version is defined, 2 physical relations are created
17-
*<vname>_added and <vname>_deleted.
15+
*At the point the version is defined, 2 physical relations are created
16+
*<vname>_added and <vname>_deleted.
1817
*
19-
*In addition, 4 rules are defined which govern the semantics ofversions
20-
* w.r.t retrieves, appends, replaces and deletes.
18+
*In addition, 4 rules are defined which govern the semantics of
19+
*versions w.r.t retrieves, appends, replaces and deletes.
2120
*
2221
*-------------------------------------------------------------------------
2322
*/

‎src/backend/commands/user.c

Lines changed: 65 additions & 91 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-
*
8+
* $Id: user.c,v 1.21 1998/12/14 06:50:18 scrappy Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -35,6 +35,8 @@
3535

3636
staticvoidCheckPgUserAclNotNull(void);
3737

38+
#defineSQL_LENGTH512
39+
3840
/*---------------------------------------------------------------------
3941
* UpdatePgPwdFile
4042
*
@@ -47,27 +49,31 @@ void
4749
UpdatePgPwdFile(char*sql)
4850
{
4951

50-
char*filename;
51-
char*tempname;
52+
char*filename,
53+
*tempname;
54+
intbufsize;
5255

5356
/*
5457
* Create a temporary filename to be renamed later. This prevents the
5558
* backend from clobbering the pg_pwd file while the postmaster might
5659
* be reading from it.
5760
*/
5861
filename=crypt_getpwdfilename();
59-
tempname= (char*)malloc(strlen(filename)+12);
60-
sprintf(tempname,"%s.%d",filename,MyProcPid);
62+
bufsize=strlen(filename)+12;
63+
tempname= (char*)palloc(bufsize);
64+
snprintf(tempname,bufsize,"%s.%d",filename,MyProcPid);
6165

6266
/*
6367
* Copy the contents of pg_shadow to the pg_pwd ASCII file using a the
6468
* SEPCHAR character as the delimiter between fields. Then rename the
6569
* file to its final name.
6670
*/
67-
sprintf(sql,"copy %s to '%s' using delimiters %s",ShadowRelationName,tempname,CRYPT_PWD_FILE_SEPCHAR);
71+
snprintf(sql,QRY_LENGTH,
72+
"copy %s to '%s' using delimiters %s",
73+
ShadowRelationName,tempname,CRYPT_PWD_FILE_SEPCHAR);
6874
pg_exec_query(sql);
6975
rename(tempname,filename);
70-
free((void*)tempname);
76+
pfree((void*)tempname);
7177

7278
/*
7379
* Create a flag file the postmaster will detect the next time it
@@ -89,18 +95,17 @@ void
8995
DefineUser(CreateUserStmt*stmt)
9096
{
9197

92-
char*pg_shadow;
93-
Relationpg_shadow_rel;
94-
TupleDescpg_shadow_dsc;
95-
HeapScanDescscan;
96-
HeapTupletuple;
97-
Datumdatum;
98-
charsql[512];
99-
char*sql_end;
100-
boolexists= false,
101-
n,
102-
inblock;
103-
intmax_id=-1;
98+
char*pg_shadow,
99+
sql[SQL_LENGTH];
100+
Relationpg_shadow_rel;
101+
TupleDescpg_shadow_dsc;
102+
HeapScanDescscan;
103+
HeapTupletuple;
104+
Datumdatum;
105+
boolexists= false,
106+
n,
107+
inblock;
108+
intmax_id=-1;
104109

105110
if (stmt->password)
106111
CheckPgUserAclNotNull();
@@ -152,46 +157,23 @@ DefineUser(CreateUserStmt *stmt)
152157
RelationUnsetLockForWrite(pg_shadow_rel);
153158
heap_close(pg_shadow_rel);
154159
UserAbortTransactionBlock();
155-
elog(ERROR,"defineUser: user \"%s\" has already been created",stmt->user);
160+
elog(ERROR,
161+
"defineUser: user \"%s\" has already been created",stmt->user);
156162
return;
157163
}
158164

159165
/*
160166
* Build the insert statment to be executed.
161167
*/
162-
sprintf(sql,"insert into %s(usename,usesysid,usecreatedb,usetrace,usesuper,usecatupd,passwd",ShadowRelationName);
163-
/*if (stmt->password)
164-
strcat(sql, ",passwd"); -- removed so that insert empty string when no password */
165-
if (stmt->validUntil)
166-
strcat(sql,",valuntil");
167-
168-
sql_end=sql+strlen(sql);
169-
sprintf(sql_end,") values('%s',%d",stmt->user,max_id+1);
170-
if (stmt->createdb&&*stmt->createdb)
171-
strcat(sql_end,",'t','t'");
172-
else
173-
strcat(sql_end,",'f','t'");
174-
if (stmt->createuser&&*stmt->createuser)
175-
strcat(sql_end,",'t','t'");
176-
else
177-
strcat(sql_end,",'f','t'");
178-
sql_end+=strlen(sql_end);
179-
if (stmt->password)
180-
{
181-
sprintf(sql_end,",'%s'",stmt->password);
182-
sql_end+=strlen(sql_end);
183-
}
184-
else
185-
{
186-
strcpy(sql_end,",''");
187-
sql_end+=strlen(sql_end);
188-
}
189-
if (stmt->validUntil)
190-
{
191-
sprintf(sql_end,",'%s'",stmt->validUntil);
192-
sql_end+=strlen(sql_end);
193-
}
194-
strcat(sql_end,")");
168+
snprintf(sql,SQL_LENGTH,
169+
"insert into %s(usename,usesysid,usecreatedb,usetrace,usesuper,"
170+
"usecatupd,passwd,valuntil) values('%s',%d%s%s,'%s','%s')",
171+
ShadowRelationName,
172+
stmt->user,max_id+1,
173+
(stmt->createdb&&*stmt->createdb) ?",'t','t'" :",'f','t'",
174+
(stmt->createuser&&*stmt->createuser) ?",'t','t'" :",'f','t'",
175+
stmt->password ?stmt->password :"''",
176+
stmt->validUntil ?stmt->valudUntil :"");
195177

196178
pg_exec_query(sql);
197179

@@ -217,13 +199,12 @@ extern void
217199
AlterUser(AlterUserStmt*stmt)
218200
{
219201

220-
char*pg_shadow;
202+
char*pg_shadow,
203+
sql[SQL_LENGTH];
221204
Relationpg_shadow_rel;
222205
TupleDescpg_shadow_dsc;
223206
HeapTupletuple;
224-
charsql[512];
225-
char*sql_end;
226-
boolinblock;
207+
boolinblock;
227208

228209
if (stmt->password)
229210
CheckPgUserAclNotNull();
@@ -271,47 +252,38 @@ AlterUser(AlterUserStmt *stmt)
271252
/*
272253
* Create the update statement to modify the user.
273254
*/
274-
sprintf(sql,"update %s set",ShadowRelationName);
275-
sql_end=sql;
255+
snprintf(sql,SQL_LENGTH,"update %s set",ShadowRelationName);
256+
276257
if (stmt->password)
277258
{
278-
sql_end+=strlen(sql_end);
279-
sprintf(sql_end," passwd = '%s'",stmt->password);
259+
snprintf(sql,SQL_LENGTH,"%s passwd = '%s'",sql,stmt->password);
280260
}
261+
281262
if (stmt->createdb)
282263
{
283-
if (sql_end!=sql)
284-
strcat(sql_end,",");
285-
sql_end+=strlen(sql_end);
286-
if (*stmt->createdb)
287-
strcat(sql_end," usecreatedb = 't'");
288-
else
289-
strcat(sql_end," usecreatedb = 'f'");
264+
snprintf(sql,SQL_LENGTH,"%s %susecreatedb='%s'",
265+
stmt->password ?"," :"",
266+
*stmt->createdb ?"t" :"f");
290267
}
268+
291269
if (stmt->createuser)
292270
{
293-
if (sql_end!=sql)
294-
strcat(sql_end,",");
295-
sql_end+=strlen(sql_end);
296-
if (*stmt->createuser)
297-
strcat(sql_end," usesuper = 't'");
298-
else
299-
strcat(sql_end," usesuper = 'f'");
271+
snprintf(sql,SQL_LENGTH,"%s %susesuper='%s'",
272+
(stmt->password||stmt->createdb) ?"," :"",
273+
*stmt->createuser ?"t" :"f");
300274
}
275+
301276
if (stmt->validUntil)
302277
{
303-
if (sql_end!=sql)
304-
strcat(sql_end,",");
305-
sql_end+=strlen(sql_end);
306-
sprintf(sql_end," valuntil = '%s'",stmt->validUntil);
307-
}
308-
if (sql_end!=sql)
309-
{
310-
sql_end+=strlen(sql_end);
311-
sprintf(sql_end," where usename = '%s'",stmt->user);
312-
pg_exec_query(sql);
278+
snprintf(sql,SQL_LENGTH,"%s %svaluntil='%s'",
279+
(stmt->password||stmt->createdb||stmt->createuser) ?"," :"",
280+
stmt->validUntil);
313281
}
314282

283+
snprintf(sql,SQL_LENGTH,"%s where usename = '%s'",sql,stmt->user);
284+
285+
pg_exec_query(sql);
286+
315287
/* do the pg_group stuff here */
316288

317289
UpdatePgPwdFile(sql);
@@ -402,8 +374,9 @@ RemoveUser(char *user)
402374
datum=heap_getattr(tuple,Anum_pg_database_datname,pg_dsc,&n);
403375
if (memcmp((void*)datum,"template1",9))
404376
{
405-
dbase= (char**)realloc((void*)dbase,sizeof(char*)* (ndbase+1));
406-
dbase[ndbase]= (char*)malloc(NAMEDATALEN+1);
377+
dbase=
378+
(char**)repalloc((void*)dbase,sizeof(char*)* (ndbase+1));
379+
dbase[ndbase]= (char*)palloc(NAMEDATALEN+1);
407380
memcpy((void*)dbase[ndbase], (void*)datum,NAMEDATALEN);
408381
dbase[ndbase++][NAMEDATALEN]='\0';
409382
}
@@ -415,12 +388,12 @@ RemoveUser(char *user)
415388
while (ndbase--)
416389
{
417390
elog(NOTICE,"Dropping database %s",dbase[ndbase]);
418-
sprintf(sql,"drop database %s",dbase[ndbase]);
419-
free((void*)dbase[ndbase]);
391+
snprintf(sql,SQL_LENGTH,"drop database %s",dbase[ndbase]);
392+
pfree((void*)dbase[ndbase]);
420393
pg_exec_query(sql);
421394
}
422395
if (dbase)
423-
free((void*)dbase);
396+
pfree((void*)dbase);
424397

425398
/*
426399
* Since pg_shadow is global over all databases, one of two things
@@ -443,7 +416,8 @@ RemoveUser(char *user)
443416
/*
444417
* Remove the user from the pg_shadow table
445418
*/
446-
sprintf(sql,"delete from %s where usename = '%s'",ShadowRelationName,user);
419+
snprintf(sql,SQL_LENGTH,
420+
"delete from %s where usename = '%s'",ShadowRelationName,user);
447421
pg_exec_query(sql);
448422

449423
UpdatePgPwdFile(sql);

‎src/backend/commands/view.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
*
9-
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/view.c,v 1.27 1998/12/14 05:18:44 scrappy Exp $
8+
* $Id: view.c,v 1.28 1998/12/14 06:50:18 scrappy Exp $
119
*
1210
*-------------------------------------------------------------------------
1311
*/

‎src/backend/executor/execAmi.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
*
9-
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/executor/execAmi.c,v 1.26 1998/12/14 05:18:49 scrappy Exp $
8+
* $Id: execAmi.c,v 1.27 1998/12/14 06:50:20 scrappy Exp $
119
*
1210
*-------------------------------------------------------------------------
1311
*/

‎src/backend/executor/nodeHash.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
* Copyright (c) 1994, Regents of the University of California
77
*
88
*
9-
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHash.c,v 1.25 1998/12/14 05:18:50 scrappy Exp $
9+
* $Id: nodeHash.c,v 1.26 1998/12/14 06:50:21 scrappy Exp $
1110
*
1211
*-------------------------------------------------------------------------
1312
*/

‎src/backend/executor/nodeTee.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
* Copyright (c) 1994, Regents of the University of California
77
*
88
* DESCRIPTION
9-
*This code provides support for a tee node, which allowsmultiple
10-
* parent in a megaplan.
9+
*This code provides support for a tee node, which allows
10+
* multiple parent in a megaplan.
1111
*
1212
* INTERFACE ROUTINES
1313
*ExecTee
1414
*ExecInitTee
1515
*ExecEndTee
1616
*
17-
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/executor/Attic/nodeTee.c,v 1.26 1998/12/14 05:18:51 scrappy Exp $
17+
* $Id: nodeTee.c,v 1.27 1998/12/14 06:50:22 scrappy Exp $
1918
*
2019
*-------------------------------------------------------------------------
2120
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp