Yet more elimination of dead stores and useless initializations.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 5 Sep 2020 17:17:32 +0000 (13:17 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 5 Sep 2020 17:17:32 +0000 (13:17 -0400)
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

src/backend/access/common/heaptuple.c
src/backend/access/gist/gistutil.c
src/backend/access/nbtree/nbtsearch.c
src/backend/catalog/storage.c
src/backend/commands/async.c
src/backend/storage/ipc/procarray.c
src/backend/tsearch/spell.c
src/backend/utils/adt/formatting.c
src/backend/utils/adt/tsrank.c
src/bin/pg_dump/pg_backup_custom.c

index f89769f37937448858ae44d5982536b29c5fb38b..f08221eed3c9a8105b497f3ce890af21037e905b 100644 (file)
@@ -736,7 +736,7 @@ expand_tuple(HeapTuple *targetHeapTuple,
 {
        AttrMissing *attrmiss = NULL;
        int                     attnum;
-       int                     firstmissingnum = 0;
+       int                     firstmissingnum;
        bool            hasNulls = HeapTupleHasNulls(sourceTuple);
        HeapTupleHeader targetTHeader;
        HeapTupleHeader sourceTHeader = sourceTuple->t_data;
index bfda7fbe3d586110094e0bf6f6678de2407b96b9..0516059e3ddc9d6b7705e6eb3f580e1054f863b7 100644 (file)
@@ -32,7 +32,6 @@
 void
 gistfillbuffer(Page page, IndexTuple *itup, int len, OffsetNumber off)
 {
-       OffsetNumber l = InvalidOffsetNumber;
        int                     i;
 
        if (off == InvalidOffsetNumber)
@@ -42,6 +41,7 @@ gistfillbuffer(Page page, IndexTuple *itup, int len, OffsetNumber off)
        for (i = 0; i < len; i++)
        {
                Size            sz = IndexTupleSize(itup[i]);
+               OffsetNumber l;
 
                l = PageAddItem(page, (Item) itup[i], sz, off, false, false);
                if (l == InvalidOffsetNumber)
index 28dc196b55e3e64837532c39cc661e37bd7ff11d..1e628a33d77ecec5beba30ad06a07ae5cd5bc4bd 100644 (file)
@@ -860,7 +860,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
        ScanKeyData notnullkeys[INDEX_MAX_KEYS];
        int                     keysCount = 0;
        int                     i;
-       bool            status = true;
+       bool            status;
        StrategyNumber strat_total;
        BTScanPosItem *currItem;
        BlockNumber blkno;
@@ -1858,7 +1858,7 @@ _bt_steppage(IndexScanDesc scan, ScanDirection dir)
 {
        BTScanOpaque so = (BTScanOpaque) scan->opaque;
        BlockNumber blkno = InvalidBlockNumber;
-       bool            status = true;
+       bool            status;
 
        Assert(BTScanPosIsValid(so->currPos));
 
@@ -1967,7 +1967,7 @@ _bt_readnextpage(IndexScanDesc scan, BlockNumber blkno, ScanDirection dir)
        Relation        rel;
        Page            page;
        BTPageOpaque opaque;
-       bool            status = true;
+       bool            status;
 
        rel = scan->indexRelation;
 
index 9e6e6c42d3c8372b6a8c5c0a9c0612f8c11724a0..dbbd3aa31fe14281ba5d4fedf0d777be1022116e 100644 (file)
@@ -599,7 +599,6 @@ smgrDoPendingDeletes(bool isCommit)
        PendingRelDelete *prev;
        PendingRelDelete *next;
        int                     nrels = 0,
-                               i = 0,
                                maxrels = 0;
        SMgrRelation *srels = NULL;
 
@@ -650,7 +649,7 @@ smgrDoPendingDeletes(bool isCommit)
        {
                smgrdounlinkall(srels, nrels, false);
 
-               for (i = 0; i < nrels; i++)
+               for (int i = 0; i < nrels; i++)
                        smgrclose(srels[i]);
 
                pfree(srels);
index 774b26fd2c4d22e89fc932ec08c7250e2d9262a1..cb341365df4652d0d7e00037deb1452280ffa9da 100644 (file)
@@ -1918,7 +1918,6 @@ static void
 asyncQueueReadAllNotifications(void)
 {
        volatile QueuePosition pos;
-       QueuePosition oldpos;
        QueuePosition head;
        Snapshot        snapshot;
 
@@ -1933,7 +1932,7 @@ asyncQueueReadAllNotifications(void)
        LWLockAcquire(NotifyQueueLock, LW_SHARED);
        /* Assert checks that we have a valid state entry */
        Assert(MyProcPid == QUEUE_BACKEND_PID(MyBackendId));
-       pos = oldpos = QUEUE_BACKEND_POS(MyBackendId);
+       pos = QUEUE_BACKEND_POS(MyBackendId);
        head = QUEUE_HEAD;
        LWLockRelease(NotifyQueueLock);
 
index a023090fbbd3d0ab2efc090d19d3086aa995dfd7..1c0cd6b2487b9468cf8929f1e7e6af11d6f448d6 100644 (file)
@@ -3433,7 +3433,6 @@ CancelDBBackends(Oid databaseid, ProcSignalReason sigmode, bool conflictPending)
 {
        ProcArrayStruct *arrayP = procArray;
        int                     index;
-       pid_t           pid = 0;
 
        /* tell all backends to die */
        LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
@@ -3446,6 +3445,7 @@ CancelDBBackends(Oid databaseid, ProcSignalReason sigmode, bool conflictPending)
                if (databaseid == InvalidOid || proc->databaseId == databaseid)
                {
                        VirtualTransactionId procvxid;
+                       pid_t           pid;
 
                        GET_VXID_FROM_PGPROC(procvxid, *proc);
 
index 49735bc06af8d35c29a81ae01e8a1c49c04ec733..05d08cfc0102d09492080063b2e113b24e8d8564 100644 (file)
@@ -1710,7 +1710,7 @@ void
 NISortDictionary(IspellDict *Conf)
 {
        int                     i;
-       int                     naffix = 0;
+       int                     naffix;
        int                     curaffix;
 
        /* compress affixes */
index bf9643ffb4a108462e4c4e745c7e1664cb81f1d1..7d09537d82b95caa7ca6817aafab3baafca228a9 100644 (file)
@@ -1510,8 +1510,7 @@ static const char *
 get_th(char *num, int type)
 {
        int                     len = strlen(num),
-                               last,
-                               seclast;
+                               last;
 
        last = *(num + (len - 1));
        if (!isdigit((unsigned char) last))
@@ -1523,7 +1522,7 @@ get_th(char *num, int type)
         * All "teens" (<x>1[0-9]) get 'TH/th', while <x>[02-9][123] still get
         * 'ST/st', 'ND/nd', 'RD/rd', respectively
         */
-       if ((len > 1) && ((seclast = num[len - 2]) == '1'))
+       if ((len > 1) && (num[len - 2] == '1'))
                last = 0;
 
        switch (last)
@@ -4932,9 +4931,9 @@ NUM_cache(int len, NUMDesc *Num, text *pars_str, bool *shouldFree)
 static char *
 int_to_roman(int number)
 {
-       int                     len = 0,
-                               num = 0;
-       char       *p = NULL,
+       int                     len,
+                               num;
+       char       *p,
                           *result,
                                numstr[12];
 
@@ -4950,7 +4949,7 @@ int_to_roman(int number)
 
        for (p = numstr; *p != '\0'; p++, --len)
        {
-               num = *p - 49;                  /* 48 ascii + 1 */
+               num = *p - ('0' + 1);
                if (num < 0)
                        continue;
 
@@ -6118,7 +6117,7 @@ numeric_to_char(PG_FUNCTION_ARGS)
                x = DatumGetNumeric(DirectFunctionCall2(numeric_round,
                                                                                                NumericGetDatum(value),
                                                                                                Int32GetDatum(0)));
-               numstr = orgnum =
+               numstr =
                        int_to_roman(DatumGetInt32(DirectFunctionCall1(numeric_int4,
                                                                                                                   NumericGetDatum(x))));
        }
@@ -6239,7 +6238,7 @@ int4_to_char(PG_FUNCTION_ARGS)
         * On DateType depend part (int32)
         */
        if (IS_ROMAN(&Num))
-               numstr = orgnum = int_to_roman(value);
+               numstr = int_to_roman(value);
        else if (IS_EEEE(&Num))
        {
                /* we can do it easily because float8 won't lose any precision */
@@ -6335,7 +6334,7 @@ int8_to_char(PG_FUNCTION_ARGS)
        if (IS_ROMAN(&Num))
        {
                /* Currently don't support int8 conversion to roman... */
-               numstr = orgnum = int_to_roman(DatumGetInt32(DirectFunctionCall1(int84, Int64GetDatum(value))));
+               numstr = int_to_roman(DatumGetInt32(DirectFunctionCall1(int84, Int64GetDatum(value))));
        }
        else if (IS_EEEE(&Num))
        {
index c88ebfc7d4113f31debd1de995f3e637974b78c6..38b413f6ffff8a4414f3f291cd1bb1644e34bdf1 100644 (file)
@@ -857,8 +857,7 @@ calc_rank_cd(const float4 *arrdata, TSVector txt, TSQuery query, int method)
        double          Wdoc = 0.0;
        double          invws[lengthof(weights)];
        double          SumDist = 0.0,
-                               PrevExtPos = 0.0,
-                               CurExtPos = 0.0;
+                               PrevExtPos = 0.0;
        int                     NExtent = 0;
        QueryRepresentation qr;
 
@@ -889,6 +888,7 @@ calc_rank_cd(const float4 *arrdata, TSVector txt, TSQuery query, int method)
        {
                double          Cpos = 0.0;
                double          InvSum = 0.0;
+               double          CurExtPos;
                int                     nNoise;
                DocRepresentation *ptr = ext.begin;
 
index 971e6adf48756dfa241c2e7783fbf8f112050ce7..77d402c323e94b02b2324ab1b359a8b35811899b 100644 (file)
@@ -619,7 +619,6 @@ _skipData(ArchiveHandle *AH)
        size_t          blkLen;
        char       *buf = NULL;
        int                     buflen = 0;
-       size_t          cnt;
 
        blkLen = ReadInt(AH);
        while (blkLen != 0)
@@ -638,7 +637,7 @@ _skipData(ArchiveHandle *AH)
                                buf = (char *) pg_malloc(blkLen);
                                buflen = blkLen;
                        }
-                       if ((cnt = fread(buf, 1, blkLen, AH->FH)) != blkLen)
+                       if (fread(buf, 1, blkLen, AH->FH) != blkLen)
                        {
                                if (feof(AH->FH))
                                        fatal("could not read from input file: end of file");
@@ -664,9 +663,7 @@ _skipData(ArchiveHandle *AH)
 static int
 _WriteByte(ArchiveHandle *AH, const int i)
 {
-       int                     res;
-
-       if ((res = fputc(i, AH->FH)) == EOF)
+       if (fputc(i, AH->FH) == EOF)
                WRITE_ERROR_EXIT;
 
        return 1;