Commit a5cc4dab authored by Tom Lane's avatar Tom Lane

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