Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d97b14d

Browse files
committed
Silence compiler warnings
Rearrange a bit of code to ensure that 'mode' in LWLockRelease is obviously always set, which seems a bit cleaner and avoids a compiler warning (thanks to Robert for the suggestion!). In GetCachedPlan(), initialize 'plan' to silence a compiler warning, but also add an Assert() to make sure we don't ever actually fall through with 'plan' still being set to NULL, since we are about to dereference it. Neither of these appear to be live bugs but at least gcc 5.4.0-6ubuntu1~16.04.4 doesn't quite have the smarts to realize that. Discussion: https://www.postgresql.org/message-id/20161129152102.GR13284%40tamriel.snowman.net
1 parent 0645dac commit d97b14d

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/backend/storage/lmgr/lwlock.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -1780,15 +1780,14 @@ LWLockRelease(LWLock *lock)
17801780
* be the latest-acquired lock; so search array backwards.
17811781
*/
17821782
for (i = num_held_lwlocks; --i >= 0;)
1783-
{
17841783
if (lock == held_lwlocks[i].lock)
1785-
{
1786-
mode = held_lwlocks[i].mode;
17871784
break;
1788-
}
1789-
}
1785+
17901786
if (i < 0)
17911787
elog(ERROR, "lock %s %d is not held", T_NAME(lock), T_ID(lock));
1788+
1789+
mode = held_lwlocks[i].mode;
1790+
17921791
num_held_lwlocks--;
17931792
for (; i < num_held_lwlocks; i++)
17941793
held_lwlocks[i] = held_lwlocks[i + 1];

src/backend/utils/cache/plancache.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ CachedPlan *
11281128
GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams,
11291129
bool useResOwner)
11301130
{
1131-
CachedPlan *plan;
1131+
CachedPlan *plan = NULL;
11321132
List *qlist;
11331133
bool customplan;
11341134

@@ -1210,6 +1210,8 @@ GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams,
12101210
}
12111211
}
12121212

1213+
Assert(plan != NULL);
1214+
12131215
/* Flag the plan as in use by caller */
12141216
if (useResOwner)
12151217
ResourceOwnerEnlargePlanCacheRefs(CurrentResourceOwner);

0 commit comments

Comments
 (0)