Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a5cc4da

Browse files
committedSep 5, 2020
Yet more elimination of dead stores and useless initializations.
I'm not sure what tool Ranier was using, but the ones I contributed were found by using a newer version of scan-build than I tried before. Ranier Vilela and Tom Lane Discussion: https://postgr.es/m/CAEudQAo1+AcGppxDSg8k+zF4+Kv+eJyqzEDdbpDg58-=MQcerQ@mail.gmail.com
1 parent 8febfd1 commit a5cc4da

File tree

10 files changed

+22
-28
lines changed

10 files changed

+22
-28
lines changed
 

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ expand_tuple(HeapTuple *targetHeapTuple,
736736
{
737737
AttrMissing *attrmiss = NULL;
738738
int attnum;
739-
int firstmissingnum = 0;
739+
int firstmissingnum;
740740
bool hasNulls = HeapTupleHasNulls(sourceTuple);
741741
HeapTupleHeader targetTHeader;
742742
HeapTupleHeader sourceTHeader = sourceTuple->t_data;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
void
3333
gistfillbuffer(Page page, IndexTuple *itup, int len, OffsetNumber off)
3434
{
35-
OffsetNumber l = InvalidOffsetNumber;
3635
int i;
3736

3837
if (off == InvalidOffsetNumber)
@@ -42,6 +41,7 @@ gistfillbuffer(Page page, IndexTuple *itup, int len, OffsetNumber off)
4241
for (i = 0; i < len; i++)
4342
{
4443
Size sz = IndexTupleSize(itup[i]);
44+
OffsetNumber l;
4545

4646
l = PageAddItem(page, (Item) itup[i], sz, off, false, false);
4747
if (l == InvalidOffsetNumber)

‎src/backend/access/nbtree/nbtsearch.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
860860
ScanKeyData notnullkeys[INDEX_MAX_KEYS];
861861
int keysCount = 0;
862862
int i;
863-
bool status = true;
863+
bool status;
864864
StrategyNumber strat_total;
865865
BTScanPosItem *currItem;
866866
BlockNumber blkno;
@@ -1858,7 +1858,7 @@ _bt_steppage(IndexScanDesc scan, ScanDirection dir)
18581858
{
18591859
BTScanOpaque so = (BTScanOpaque) scan->opaque;
18601860
BlockNumber blkno = InvalidBlockNumber;
1861-
bool status = true;
1861+
bool status;
18621862

18631863
Assert(BTScanPosIsValid(so->currPos));
18641864

@@ -1967,7 +1967,7 @@ _bt_readnextpage(IndexScanDesc scan, BlockNumber blkno, ScanDirection dir)
19671967
Relation rel;
19681968
Page page;
19691969
BTPageOpaque opaque;
1970-
bool status = true;
1970+
bool status;
19711971

19721972
rel = scan->indexRelation;
19731973

‎src/backend/catalog/storage.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,6 @@ smgrDoPendingDeletes(bool isCommit)
599599
PendingRelDelete *prev;
600600
PendingRelDelete *next;
601601
int nrels = 0,
602-
i = 0,
603602
maxrels = 0;
604603
SMgrRelation *srels = NULL;
605604

@@ -650,7 +649,7 @@ smgrDoPendingDeletes(bool isCommit)
650649
{
651650
smgrdounlinkall(srels, nrels, false);
652651

653-
for (i = 0; i < nrels; i++)
652+
for (int i = 0; i < nrels; i++)
654653
smgrclose(srels[i]);
655654

656655
pfree(srels);

‎src/backend/commands/async.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,6 @@ static void
19181918
asyncQueueReadAllNotifications(void)
19191919
{
19201920
volatile QueuePosition pos;
1921-
QueuePosition oldpos;
19221921
QueuePosition head;
19231922
Snapshot snapshot;
19241923

@@ -1933,7 +1932,7 @@ asyncQueueReadAllNotifications(void)
19331932
LWLockAcquire(NotifyQueueLock, LW_SHARED);
19341933
/* Assert checks that we have a valid state entry */
19351934
Assert(MyProcPid == QUEUE_BACKEND_PID(MyBackendId));
1936-
pos = oldpos = QUEUE_BACKEND_POS(MyBackendId);
1935+
pos = QUEUE_BACKEND_POS(MyBackendId);
19371936
head = QUEUE_HEAD;
19381937
LWLockRelease(NotifyQueueLock);
19391938

‎src/backend/storage/ipc/procarray.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3433,7 +3433,6 @@ CancelDBBackends(Oid databaseid, ProcSignalReason sigmode, bool conflictPending)
34333433
{
34343434
ProcArrayStruct *arrayP = procArray;
34353435
int index;
3436-
pid_t pid = 0;
34373436

34383437
/* tell all backends to die */
34393438
LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
@@ -3446,6 +3445,7 @@ CancelDBBackends(Oid databaseid, ProcSignalReason sigmode, bool conflictPending)
34463445
if (databaseid == InvalidOid || proc->databaseId == databaseid)
34473446
{
34483447
VirtualTransactionId procvxid;
3448+
pid_t pid;
34493449

34503450
GET_VXID_FROM_PGPROC(procvxid, *proc);
34513451

‎src/backend/tsearch/spell.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,7 @@ void
17101710
NISortDictionary(IspellDict *Conf)
17111711
{
17121712
int i;
1713-
int naffix = 0;
1713+
int naffix;
17141714
int curaffix;
17151715

17161716
/* compress affixes */

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,8 +1510,7 @@ static const char *
15101510
get_th(char *num, int type)
15111511
{
15121512
int len = strlen(num),
1513-
last,
1514-
seclast;
1513+
last;
15151514

15161515
last = *(num + (len - 1));
15171516
if (!isdigit((unsigned char) last))
@@ -1523,7 +1522,7 @@ get_th(char *num, int type)
15231522
* All "teens" (<x>1[0-9]) get 'TH/th', while <x>[02-9][123] still get
15241523
* 'ST/st', 'ND/nd', 'RD/rd', respectively
15251524
*/
1526-
if ((len > 1) && ((seclast = num[len - 2]) == '1'))
1525+
if ((len > 1) && (num[len - 2] == '1'))
15271526
last = 0;
15281527

15291528
switch (last)
@@ -4932,9 +4931,9 @@ NUM_cache(int len, NUMDesc *Num, text *pars_str, bool *shouldFree)
49324931
static char *
49334932
int_to_roman(int number)
49344933
{
4935-
int len = 0,
4936-
num = 0;
4937-
char *p = NULL,
4934+
int len,
4935+
num;
4936+
char *p,
49384937
*result,
49394938
numstr[12];
49404939

@@ -4950,7 +4949,7 @@ int_to_roman(int number)
49504949

49514950
for (p = numstr; *p != '\0'; p++, --len)
49524951
{
4953-
num = *p - 49; /* 48 ascii + 1 */
4952+
num = *p - ('0' + 1);
49544953
if (num < 0)
49554954
continue;
49564955

@@ -6118,7 +6117,7 @@ numeric_to_char(PG_FUNCTION_ARGS)
61186117
x = DatumGetNumeric(DirectFunctionCall2(numeric_round,
61196118
NumericGetDatum(value),
61206119
Int32GetDatum(0)));
6121-
numstr = orgnum =
6120+
numstr =
61226121
int_to_roman(DatumGetInt32(DirectFunctionCall1(numeric_int4,
61236122
NumericGetDatum(x))));
61246123
}
@@ -6239,7 +6238,7 @@ int4_to_char(PG_FUNCTION_ARGS)
62396238
* On DateType depend part (int32)
62406239
*/
62416240
if (IS_ROMAN(&Num))
6242-
numstr = orgnum = int_to_roman(value);
6241+
numstr = int_to_roman(value);
62436242
else if (IS_EEEE(&Num))
62446243
{
62456244
/* we can do it easily because float8 won't lose any precision */
@@ -6335,7 +6334,7 @@ int8_to_char(PG_FUNCTION_ARGS)
63356334
if (IS_ROMAN(&Num))
63366335
{
63376336
/* Currently don't support int8 conversion to roman... */
6338-
numstr = orgnum = int_to_roman(DatumGetInt32(DirectFunctionCall1(int84, Int64GetDatum(value))));
6337+
numstr = int_to_roman(DatumGetInt32(DirectFunctionCall1(int84, Int64GetDatum(value))));
63396338
}
63406339
else if (IS_EEEE(&Num))
63416340
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,8 +857,7 @@ calc_rank_cd(const float4 *arrdata, TSVector txt, TSQuery query, int method)
857857
double Wdoc = 0.0;
858858
double invws[lengthof(weights)];
859859
double SumDist = 0.0,
860-
PrevExtPos = 0.0,
861-
CurExtPos = 0.0;
860+
PrevExtPos = 0.0;
862861
int NExtent = 0;
863862
QueryRepresentation qr;
864863

@@ -889,6 +888,7 @@ calc_rank_cd(const float4 *arrdata, TSVector txt, TSQuery query, int method)
889888
{
890889
double Cpos = 0.0;
891890
double InvSum = 0.0;
891+
double CurExtPos;
892892
int nNoise;
893893
DocRepresentation *ptr = ext.begin;
894894

‎src/bin/pg_dump/pg_backup_custom.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,6 @@ _skipData(ArchiveHandle *AH)
619619
size_t blkLen;
620620
char *buf = NULL;
621621
int buflen = 0;
622-
size_t cnt;
623622

624623
blkLen = ReadInt(AH);
625624
while (blkLen != 0)
@@ -638,7 +637,7 @@ _skipData(ArchiveHandle *AH)
638637
buf = (char *) pg_malloc(blkLen);
639638
buflen = blkLen;
640639
}
641-
if ((cnt = fread(buf, 1, blkLen, AH->FH)) != blkLen)
640+
if (fread(buf, 1, blkLen, AH->FH) != blkLen)
642641
{
643642
if (feof(AH->FH))
644643
fatal("could not read from input file: end of file");
@@ -664,9 +663,7 @@ _skipData(ArchiveHandle *AH)
664663
static int
665664
_WriteByte(ArchiveHandle *AH, const int i)
666665
{
667-
int res;
668-
669-
if ((res = fputc(i, AH->FH)) == EOF)
666+
if (fputc(i, AH->FH) == EOF)
670667
WRITE_ERROR_EXIT;
671668

672669
return 1;

0 commit comments

Comments
 (0)
Please sign in to comment.