Initialize unused ExprEvalStep fields.
authorAndres Freund <andres@anarazel.de>
Wed, 24 Jan 2018 07:20:02 +0000 (23:20 -0800)
committerAndres Freund <andres@anarazel.de>
Mon, 29 Jan 2018 20:01:07 +0000 (12:01 -0800)
ExecPushExprSlots didn't initialize ExprEvalStep's resvalue/resnull
steps as it didn't use them. That caused wrong valgrind warnings for
an upcoming patch, so zero-intialize.

Also zero-initialize all scratch ExprEvalStep's allocated on the
stack, to avoid issues with similar future omissions of non-critial
data.

src/backend/executor/execExpr.c

index 883a29f0a7bbf87fd8aea6548837fd2612c5344c..c6eb3ebacf8e110cc2095f2a701099a3d5db59b2 100644 (file)
@@ -118,7 +118,7 @@ ExprState *
 ExecInitExpr(Expr *node, PlanState *parent)
 {
        ExprState  *state;
-       ExprEvalStep scratch;
+       ExprEvalStep scratch = {0};
 
        /* Special case: NULL expression produces a NULL ExprState pointer */
        if (node == NULL)
@@ -155,7 +155,7 @@ ExprState *
 ExecInitExprWithParams(Expr *node, ParamListInfo ext_params)
 {
        ExprState  *state;
-       ExprEvalStep scratch;
+       ExprEvalStep scratch = {0};
 
        /* Special case: NULL expression produces a NULL ExprState pointer */
        if (node == NULL)
@@ -204,7 +204,7 @@ ExprState *
 ExecInitQual(List *qual, PlanState *parent)
 {
        ExprState  *state;
-       ExprEvalStep scratch;
+       ExprEvalStep scratch = {0};
        List       *adjust_jumps = NIL;
        ListCell   *lc;
 
@@ -353,7 +353,7 @@ ExecBuildProjectionInfo(List *targetList,
 {
        ProjectionInfo *projInfo = makeNode(ProjectionInfo);
        ExprState  *state;
-       ExprEvalStep scratch;
+       ExprEvalStep scratch = {0};
        ListCell   *lc;
 
        projInfo->pi_exprContext = econtext;
@@ -638,7 +638,7 @@ static void
 ExecInitExprRec(Expr *node, ExprState *state,
                                Datum *resv, bool *resnull)
 {
-       ExprEvalStep scratch;
+       ExprEvalStep scratch = {0};
 
        /* Guard against stack overflow due to overly complex expressions */
        check_stack_depth();
@@ -2273,7 +2273,10 @@ ExecInitExprSlots(ExprState *state, Node *node)
 static void
 ExecPushExprSlots(ExprState *state, LastAttnumInfo *info)
 {
-       ExprEvalStep scratch;
+       ExprEvalStep scratch = {0};
+
+       scratch.resvalue = NULL;
+       scratch.resnull = NULL;
 
        /* Emit steps as needed */
        if (info->last_inner > 0)
@@ -2659,7 +2662,7 @@ static void
 ExecInitCoerceToDomain(ExprEvalStep *scratch, CoerceToDomain *ctest,
                                           ExprState *state, Datum *resv, bool *resnull)
 {
-       ExprEvalStep scratch2;
+       ExprEvalStep scratch2 = {0};
        DomainConstraintRef *constraint_ref;
        Datum      *domainval = NULL;
        bool       *domainnull = NULL;
@@ -2811,7 +2814,7 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
 {
        ExprState  *state = makeNode(ExprState);
        PlanState  *parent = &aggstate->ss.ps;
-       ExprEvalStep scratch;
+       ExprEvalStep scratch = {0};
        int                     transno = 0;
        int                     setoff = 0;
        bool            isCombine = DO_AGGSPLIT_COMBINE(aggstate->aggsplit);