aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_expr.c
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2022-04-14 08:57:09 -0400
committerAndrew Dunstan <andrew@dunslane.net>2022-04-14 09:24:22 -0400
commitfcdb35c32ac70a113c134a66daf9ba28523ff32b (patch)
tree5970643f7b8a9810581c3eb664e1b103ccef0374 /src/backend/parser/parse_expr.c
parentcd4868a5700fadf5a840d44686658517433b338c (diff)
downloadpostgresql-fcdb35c32ac70a113c134a66daf9ba28523ff32b.tar.gz
postgresql-fcdb35c32ac70a113c134a66daf9ba28523ff32b.zip
Fix transformJsonBehavior
Commit 1a36bc9dba8 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.
Diffstat (limited to 'src/backend/parser/parse_expr.c')
-rw-r--r--src/backend/parser/parse_expr.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 3cbd5161528..2f8c5e63fe8 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -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);
}