Commit d97b14dd authored by Stephen Frost's avatar Stephen Frost

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
parent 0645dacc
...@@ -1780,15 +1780,14 @@ LWLockRelease(LWLock *lock) ...@@ -1780,15 +1780,14 @@ LWLockRelease(LWLock *lock)
* be the latest-acquired lock; so search array backwards. * be the latest-acquired lock; so search array backwards.
*/ */
for (i = num_held_lwlocks; --i >= 0;) for (i = num_held_lwlocks; --i >= 0;)
{
if (lock == held_lwlocks[i].lock) if (lock == held_lwlocks[i].lock)
{
mode = held_lwlocks[i].mode;
break; break;
}
}
if (i < 0) if (i < 0)
elog(ERROR, "lock %s %d is not held", T_NAME(lock), T_ID(lock)); elog(ERROR, "lock %s %d is not held", T_NAME(lock), T_ID(lock));
mode = held_lwlocks[i].mode;
num_held_lwlocks--; num_held_lwlocks--;
for (; i < num_held_lwlocks; i++) for (; i < num_held_lwlocks; i++)
held_lwlocks[i] = held_lwlocks[i + 1]; held_lwlocks[i] = held_lwlocks[i + 1];
......
...@@ -1128,7 +1128,7 @@ CachedPlan * ...@@ -1128,7 +1128,7 @@ CachedPlan *
GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams, GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams,
bool useResOwner) bool useResOwner)
{ {
CachedPlan *plan; CachedPlan *plan = NULL;
List *qlist; List *qlist;
bool customplan; bool customplan;
...@@ -1210,6 +1210,8 @@ GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams, ...@@ -1210,6 +1210,8 @@ GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams,
} }
} }
Assert(plan != NULL);
/* Flag the plan as in use by caller */ /* Flag the plan as in use by caller */
if (useResOwner) if (useResOwner)
ResourceOwnerEnlargePlanCacheRefs(CurrentResourceOwner); ResourceOwnerEnlargePlanCacheRefs(CurrentResourceOwner);
......
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