Fix transformJsonBehavior

Commit 1a36bc9dba conained some logic that was a little opaque and
could have involved a NULL dereference, as complained about by Coverity.
Make the logic more transparent and in doing so avoid the NULL
dereference.
This commit is contained in:
Andrew Dunstan 2022-04-14 08:57:09 -04:00
parent cd4868a570
commit fcdb35c32a
1 changed files with 8 additions and 6 deletions

View File

@ -4072,13 +4072,15 @@ static JsonBehavior *
transformJsonBehavior(ParseState *pstate, JsonBehavior *behavior,
JsonBehaviorType default_behavior)
{
JsonBehaviorType behavior_type;
Node *default_expr;
behavior_type = behavior ? behavior->btype : default_behavior;
default_expr = behavior_type != JSON_BEHAVIOR_DEFAULT ? NULL :
transformExprRecurse(pstate, behavior->default_expr);
JsonBehaviorType behavior_type = default_behavior;
Node *default_expr = NULL;
if (behavior)
{
behavior_type = behavior->btype;
if (behavior_type == JSON_BEHAVIOR_DEFAULT)
default_expr = transformExprRecurse(pstate, behavior->default_expr);
}
return makeJsonBehavior(behavior_type, default_expr);
}