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

Commit7c3b7d2

Browse files
committed
Initial attempt to clean up the code...Switch sprintf() to snprintf()Remove any/all #if 0 -or- #ifdef NOT_USED -or- #ifdef FALSE sections ofcode
1 parentf722af6 commit7c3b7d2

File tree

21 files changed

+5613
-5527
lines changed

21 files changed

+5613
-5527
lines changed

‎src/backend/access/common/tupdesc.c

Lines changed: 3 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/access/common/tupdesc.c,v 1.45 1998/11/27 19:51:28 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.46 1998/12/14 05:18:30 scrappy Exp $
1111
*
1212
* NOTES
1313
* some of the executor utility code such as "ExecTypeFromTL" should be
@@ -488,7 +488,8 @@ BuildDescForRelation(List *schema, char *relname)
488488
if (arry!=NIL)
489489
{
490490
/* array of XXX is _XXX */
491-
sprintf(typename,"_%.*s",NAMEDATALEN-2,entry->typename->name);
491+
snprintf(typename,NAMEDATALEN,
492+
"_%.*s",NAMEDATALEN-2,entry->typename->name);
492493
attdim=length(arry);
493494
}
494495
else

‎src/backend/access/gist/gist.c

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,34 +1326,6 @@ _gistdump(Relation r)
13261326
}
13271327
}
13281328

1329-
#ifdefNOT_USED
1330-
staticchar*
1331-
text_range_out(TXTRANGE*r)
1332-
{
1333-
char*result;
1334-
char*lower,
1335-
*upper;
1336-
1337-
if (r==NULL)
1338-
returnNULL;
1339-
result= (char*)palloc(NAMEDATALEN+VARSIZE(TRLOWER(r))+VARSIZE(TRUPPER(r))
1340-
-2*VARHDRSZ);
1341-
1342-
lower= (char*)palloc(VARSIZE(TRLOWER(r))+1-VARHDRSZ);
1343-
memcpy(lower,VARDATA(TRLOWER(r)),VARSIZE(TRLOWER(r))-VARHDRSZ);
1344-
lower[VARSIZE(TRLOWER(r))-VARHDRSZ]='\0';
1345-
upper= (char*)palloc(VARSIZE(TRUPPER(r))+1-VARHDRSZ);
1346-
memcpy(upper,VARDATA(TRUPPER(r)),VARSIZE(TRUPPER(r))-VARHDRSZ);
1347-
upper[VARSIZE(TRUPPER(r))-VARHDRSZ]='\0';
1348-
1349-
sprintf(result,"[%s,%s): %d",lower,upper,r->flag);
1350-
pfree(lower);
1351-
pfree(upper);
1352-
returnresult;
1353-
}
1354-
1355-
#endif
1356-
13571329
staticchar*
13581330
int_range_out(INTRANGE*r)
13591331
{
@@ -1362,7 +1334,7 @@ int_range_out(INTRANGE *r)
13621334
if (r==NULL)
13631335
returnNULL;
13641336
result= (char*)palloc(80);
1365-
sprintf(result,"[%d,%d): %d",r->lower,r->upper,r->flag);
1337+
snprintf(result,80,"[%d,%d): %d",r->lower,r->upper,r->flag);
13661338

13671339
returnresult;
13681340
}

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

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/xid.c,v 1.18 1998/10/08 18:29:18 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/xid.c,v 1.19 1998/12/14 05:18:33 scrappy Exp $
1111
*
1212
* OLD COMMENTS
1313
* XXX WARNING
@@ -53,18 +53,6 @@ xidout(TransactionId transactionId)
5353

5454
}
5555

56-
#ifdefNOT_USED
57-
/* ----------------------------------------------------------------
58-
*TransactionIdIsLessThan
59-
* ----------------------------------------------------------------
60-
*/
61-
bool
62-
TransactionIdIsLessThan(TransactionIdid1,TransactionIdid2)
63-
{
64-
return (bool) (id1<id2);
65-
}
66-
#endif
67-
6856
/* ----------------------------------------------------------------
6957
*xideq
7058
* ----------------------------------------------------------------
@@ -82,23 +70,6 @@ xideq(TransactionId xid1, TransactionId xid2)
8270

8371

8472

85-
/* ----------------------------------------------------------------
86-
*TransactionIdIncrement
87-
* ----------------------------------------------------------------
88-
*/
89-
#ifdefNOT_USED
90-
void
91-
TransactionIdIncrement(TransactionId*transactionId)
92-
{
93-
94-
(*transactionId)++;
95-
if (*transactionId==DisabledTransactionId)
96-
elog(FATAL,"TransactionIdIncrement: exhausted XID's");
97-
return;
98-
}
99-
100-
#endif
101-
10273
/* ----------------------------------------------------------------
10374
*TransactionIdAdd
10475
* ----------------------------------------------------------------

‎src/backend/catalog/catalog.c

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.18 1998/09/01 04:27:28 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.19 1998/12/14 05:18:36 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -29,40 +29,19 @@
2929
char*
3030
relpath(char*relname)
3131
{
32-
char*path;
32+
char*path;
33+
intbufsize=0;
3334

3435
if (IsSharedSystemRelationName(relname))
3536
{
36-
path= (char*)palloc(strlen(DataDir)+sizeof(NameData)+2);
37-
sprintf(path,"%s/%s",DataDir,relname);
37+
bufsize=strlen(DataDir)+sizeof(NameData)+2;
38+
path= (char*)palloc(bufsize);
39+
snprintf(path,bufsize,"%s/%s",DataDir,relname);
3840
returnpath;
3941
}
4042
returnrelname;
4143
}
4244

43-
#ifdefNOT_USED
44-
/*
45-
* issystem- returns non-zero iff relname is a system catalog
46-
*
47-
*We now make a new requirement where system catalog relns must begin
48-
*with pg_ while user relns are forbidden to do so. Make the test
49-
*trivial and instantaneous.
50-
*
51-
*XXX this is way bogus. -- pma
52-
*/
53-
bool
54-
issystem(char*relname)
55-
{
56-
if (relname[0]&&relname[1]&&relname[2])
57-
return (relname[0]=='p'&&
58-
relname[1]=='g'&&
59-
relname[2]=='_');
60-
else
61-
return FALSE;
62-
}
63-
64-
#endif
65-
6645
/*
6746
* IsSystemRelationName --
6847
*True iff name is the name of a system catalog relation.

‎src/backend/catalog/heap.c

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.68 1998/12/13 23:50:58 thomas Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.69 1998/12/14 05:18:37 scrappy Exp $
1111
*
1212
* INTERFACE ROUTINES
1313
*heap_create()- Create an uncataloged heap relation
@@ -244,7 +244,7 @@ heap_create(char *name,
244244

245245
if (name[0]=='\0')
246246
{
247-
sprintf(tempname,"temp_%d",relid);
247+
snprintf(tempname,NAMEDATALEN,"temp_%d",relid);
248248
Assert(strlen(tempname)<NAMEDATALEN);
249249
relname=tempname;
250250
isTemp=1;
@@ -1448,8 +1448,9 @@ start:;
14481448
/* Surround table name with double quotes to allow mixed-case and
14491449
* whitespaces in names. - BGA 1998-11-14
14501450
*/
1451-
sprintf(str,"select %s%s from \"%.*s\"",attrdef->adsrc,cast,
1452-
NAMEDATALEN,rel->rd_rel->relname.data);
1451+
snprintf(str,MAX_PARSE_BUFFER,
1452+
"select %s%s from \"%.*s\"",attrdef->adsrc,cast,
1453+
NAMEDATALEN,rel->rd_rel->relname.data);
14531454
setheapoverride(true);
14541455
planTree_list= (List*)pg_parse_and_plan(str,NULL,0,&queryTree_list,None, FALSE);
14551456
setheapoverride(false);
@@ -1463,22 +1464,6 @@ start:;
14631464
expr=te->expr;
14641465
type=exprType(expr);
14651466

1466-
#if0
1467-
if (IsA(expr,Const))
1468-
{
1469-
if (((Const*)expr)->consttype!=atp->atttypid)
1470-
{
1471-
if (*cast!=0)
1472-
elog(ERROR,"DEFAULT: const type mismatched");
1473-
sprintf(cast,":: %s",typeidTypeName(atp->atttypid));
1474-
gotostart;
1475-
}
1476-
}
1477-
elseif ((exprType(expr)!=atp->atttypid)
1478-
&& !IS_BINARY_COMPATIBLE(exprType(expr),atp->atttypid))
1479-
elog(ERROR,"DEFAULT: type mismatched");
1480-
#endif
1481-
14821467
if (type!=atp->atttypid)
14831468
{
14841469
if (IS_BINARY_COMPATIBLE(type,atp->atttypid))
@@ -1490,7 +1475,7 @@ start:;
14901475
if (*cast!=0)
14911476
elog(ERROR,"DEFAULT clause const type '%s' mismatched with column type '%s'",
14921477
typeidTypeName(type),typeidTypeName(atp->atttypid));
1493-
sprintf(cast,":: %s",typeidTypeName(atp->atttypid));
1478+
snprintf(cast,2*NAMEDATALEN,":: %s",typeidTypeName(atp->atttypid));
14941479
gotostart;
14951480
}
14961481
else
@@ -1544,7 +1529,8 @@ StoreRelCheck(Relation rel, ConstrCheck *check)
15441529
/* Check for table's existance. Surround table name with double-quotes
15451530
* to allow mixed-case and whitespace names. - thomas 1998-11-12
15461531
*/
1547-
sprintf(str,"select 1 from \"%.*s\" where %s",
1532+
snprintf(str,MAX_PARSE_BUFFER,
1533+
"select 1 from \"%.*s\" where %s",
15481534
NAMEDATALEN,rel->rd_rel->relname.data,check->ccsrc);
15491535
setheapoverride(true);
15501536
planTree_list= (List*)pg_parse_and_plan(str,NULL,0,&queryTree_list,None, FALSE);

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/commands/_deadcode/Attic/version.c,v 1.15 1998/09/01 04:28:09 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/commands/_deadcode/Attic/version.c,v 1.16 1998/12/14 05:18:44 scrappy Exp $
1414
*
1515
* NOTES
1616
* At the point the version is defined, 2 physical relations are created
@@ -37,11 +37,6 @@
3737

3838
charrule_buf[MAX_QUERY_LEN];
3939

40-
#ifdefNOT_USED
41-
staticcharattr_list[MAX_QUERY_LEN];
42-
43-
#endif
44-
4540
/*
4641
* problem: the version system assumes that the rules it declares will
4742
*be fired in the order of declaration, it also assumes

‎src/backend/commands/cluster.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
*
1616
* IDENTIFICATION
17-
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.33 1998/11/27 19:51:54 vadim Exp $
17+
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.34 1998/12/14 05:18:39 scrappy Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -165,7 +165,7 @@ cluster(char *oldrelname, char *oldindexname)
165165

166166
/* Create new index over the tuples of the new heap. */
167167
copy_index(OIDOldIndex,OIDNewHeap);
168-
sprintf(NewIndexName,"temp_%x",OIDOldIndex);
168+
snprintf(NewIndexName,NAMEDATALEN,"temp_%x",OIDOldIndex);
169169

170170
/*
171171
* make this really happen. Flush all the buffers. (Believe me, it is
@@ -207,7 +207,7 @@ copy_heap(Oid OIDOldHeap)
207207
* Create a new heap relation with a temporary name, which has the
208208
* same tuple description as the old one.
209209
*/
210-
sprintf(NewName,"temp_%x",OIDOldHeap);
210+
snprintf(NewName,NAMEDATALEN,"temp_%x",OIDOldHeap);
211211

212212
OldHeap=heap_open(OIDOldHeap);
213213
OldHeapDesc=RelationGetDescr(OldHeap);
@@ -235,17 +235,17 @@ copy_heap(Oid OIDOldHeap)
235235
staticvoid
236236
copy_index(OidOIDOldIndex,OidOIDNewHeap)
237237
{
238-
RelationOldIndex,
239-
NewHeap;
240-
HeapTupleOld_pg_index_Tuple,
241-
Old_pg_index_relation_Tuple,
242-
pg_proc_Tuple;
238+
RelationOldIndex,
239+
NewHeap;
240+
HeapTupleOld_pg_index_Tuple,
241+
Old_pg_index_relation_Tuple,
242+
pg_proc_Tuple;
243243
Form_pg_indexOld_pg_index_Form;
244244
Form_pg_classOld_pg_index_relation_Form;
245-
Form_pg_procpg_proc_Form;
246-
char*NewIndexName;
247-
AttrNumber*attnumP;
248-
intnatts;
245+
Form_pg_procpg_proc_Form;
246+
char*NewIndexName;
247+
AttrNumber*attnumP;
248+
intnatts;
249249
FuncIndexInfo*finfo;
250250

251251
NewHeap=heap_open(OIDNewHeap);
@@ -273,8 +273,9 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap)
273273
Old_pg_index_relation_Form=
274274
(Form_pg_class)GETSTRUCT(Old_pg_index_relation_Tuple);
275275

276+
/* Set the name. */
276277
NewIndexName=palloc(NAMEDATALEN);/* XXX */
277-
sprintf(NewIndexName,"temp_%x",OIDOldIndex);/* Set the name. */
278+
snprintf(NewIndexName,NAMEDATALEN,"temp_%x",OIDOldIndex);
278279

279280
/*
280281
* Ugly as it is, the only way I have of working out the number of

‎src/backend/commands/creatinh.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.36 1998/11/27 19:51:55 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.37 1998/12/14 05:18:43 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -90,11 +90,11 @@ DefineRelation(CreateStmt *stmt, char relkind)
9090

9191
if (constraints!=NIL)
9292
{
93-
List*entry;
94-
intnconstr=length(constraints);
93+
List*entry;
94+
intnconstr=length(constraints),
95+
ncheck=0,
96+
i;
9597
ConstrCheck*check= (ConstrCheck*)palloc(nconstr*sizeof(ConstrCheck));
96-
intncheck=0;
97-
inti;
9898

9999
foreach(entry,constraints)
100100
{
@@ -107,14 +107,16 @@ DefineRelation(CreateStmt *stmt, char relkind)
107107
for (i=0;i<ncheck;i++)
108108
{
109109
if (strcmp(check[i].ccname,cdef->name)==0)
110-
elog(ERROR,"DefineRelation: name (%s) of CHECK constraint duplicated",cdef->name);
110+
elog(ERROR,
111+
"DefineRelation: name (%s) of CHECK constraint duplicated",
112+
cdef->name);
111113
}
112114
check[ncheck].ccname=cdef->name;
113115
}
114116
else
115117
{
116118
check[ncheck].ccname= (char*)palloc(NAMEDATALEN);
117-
sprintf(check[ncheck].ccname,"$%d",ncheck+1);
119+
snprintf(check[ncheck].ccname,NAMEDATALEN,"$%d",ncheck+1);
118120
}
119121
check[ncheck].ccbin=NULL;
120122
check[ncheck].ccsrc= (char*)cdef->def;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp