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

Commit02c0eb6

Browse files
author
Bryan Henderson
committed
Properly structure ProcedureNameIndexScan so it doesn't generate
"may be used before being set" warnings.
1 parentbf14017 commit02c0eb6

File tree

1 file changed

+53
-38
lines changed

1 file changed

+53
-38
lines changed

‎src/backend/catalog/indexing.c

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.6 1996/11/13 20:47:57 scrappy Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.7 1996/11/26 02:45:05 bryanh Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -352,26 +352,36 @@ ProcedureOidIndexScan(Relation heapRelation, Oid procId)
352352
returntuple;
353353
}
354354

355+
356+
355357
HeapTuple
356358
ProcedureNameIndexScan(RelationheapRelation,
357-
char*procName,
358-
intnargs,
359-
Oid*argTypes)
359+
char*procName,
360+
intnargs,
361+
Oid*argTypes)
360362
{
361363
Relationidesc;
362364
ScanKeyDataskey;
363-
HeapTupletuple;
365+
HeapTupletuple;/* tuple being tested */
366+
HeapTuplereturn_tuple;/* The tuple pointer we eventually return */
364367
IndexScanDescsd;
365368
RetrieveIndexResultindexRes;
366369
Bufferbuffer;
367370
Form_pg_procpgProcP;
368-
boolbufferUsed= FALSE;
371+
boolScanComplete;
372+
/* The index scan is complete, i.e. we've scanned everything there
373+
is to scan.
374+
*/
375+
boolFoundMatch;
376+
/* In scanning pg_proc, we have found a row that meets our search
377+
criteria.
378+
*/
369379

370380
ScanKeyEntryInitialize(&skey,
371-
(bits16)0x0,
372-
(AttrNumber)1,
373-
(RegProcedure)NameEqualRegProcedure,
374-
(Datum)procName);
381+
(bits16)0x0,
382+
(AttrNumber)1,
383+
(RegProcedure)NameEqualRegProcedure,
384+
(Datum)procName);
375385

376386
idesc=index_openr(ProcedureNameIndex);
377387

@@ -382,41 +392,46 @@ ProcedureNameIndexScan(Relation heapRelation,
382392
* by hand, so that we can check that the other keys match. when
383393
* multi-key indices are added, they will be used here.
384394
*/
385-
do {
386-
tuple= (HeapTuple)NULL;
387-
if (bufferUsed) {
388-
ReleaseBuffer(buffer);
389-
bufferUsed= FALSE;
390-
}
391-
392-
indexRes=index_getnext(sd,ForwardScanDirection);
393-
if (indexRes) {
394-
ItemPointeriptr;
395-
396-
iptr=&indexRes->heap_iptr;
397-
tuple=heap_fetch(heapRelation,NowTimeQual,iptr,&buffer);
398-
pfree(indexRes);
399-
if (HeapTupleIsValid(tuple)) {
400-
pgProcP= (Form_pg_proc)GETSTRUCT(tuple);
401-
bufferUsed= TRUE;
402-
}
403-
}else
404-
break;
405-
}while (!HeapTupleIsValid(tuple)||
406-
pgProcP->pronargs!=nargs||
407-
!oid8eq(&(pgProcP->proargtypes[0]),argTypes));
408-
409-
if (HeapTupleIsValid(tuple)) {
410-
tuple=heap_copytuple(tuple);
411-
ReleaseBuffer(buffer);
395+
tuple= (HeapTuple)NULL;/* initial value */
396+
ScanComplete= false;/* Scan hasn't begun yet */
397+
FoundMatch= false;/* No match yet; haven't even looked. */
398+
while (!FoundMatch&& !ScanComplete) {
399+
indexRes=index_getnext(sd,ForwardScanDirection);
400+
if (indexRes) {
401+
ItemPointeriptr;
402+
403+
iptr=&indexRes->heap_iptr;
404+
tuple=heap_fetch(heapRelation,NowTimeQual,iptr,&buffer);
405+
pfree(indexRes);
406+
if (HeapTupleIsValid(tuple)) {
407+
/* Here's a row for a procedure that has the sought procedure
408+
name. To be a match, though, we need it to have the
409+
right number and type of arguments too, so we check that
410+
now.
411+
*/
412+
pgProcP= (Form_pg_proc)GETSTRUCT(tuple);
413+
if (pgProcP->pronargs==nargs&&
414+
oid8eq(&(pgProcP->proargtypes[0]),argTypes))
415+
FoundMatch= true;
416+
elseReleaseBuffer(buffer);
417+
}
418+
}elseScanComplete= true;
412419
}
420+
421+
if (FoundMatch) {
422+
Assert(HeapTupleIsValid(tuple));
423+
return_tuple=heap_copytuple(tuple);
424+
ReleaseBuffer(buffer);
425+
}elsereturn_tuple= (HeapTuple)NULL;
413426

414427
index_endscan(sd);
415428
index_close(idesc);
416429

417-
returntuple;
430+
returnreturn_tuple;
418431
}
419432

433+
434+
420435
HeapTuple
421436
ProcedureSrcIndexScan(RelationheapRelation,text*procSrc)
422437
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp