From 004a8b4fd3e6c6c592aba8dbafde5516c7bc1bef Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Wed, 17 Dec 2014 11:17:33 +0100 Subject: [PATCH] Fix bug in `expr_clone` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit On allocation failure of nhls for EXPR_OP_CALL2, EXPR_OP_UP, EXPR_OP_CALL1, the correct behaviour, that is returning -1, was only effective if node->kind == EXPR_OP_CALL2 and node->u.call.own_rhs This change implements the correct behaviour. It also solves a warning when compiling with gcc4.9 that broke integration when compiling with -Werror: the compiler was hurt to use nrhs that he suspected (wrongly) to be uninitialised. Change-Id: I184fea5e121d38fa1df5d0a8680edf51e9fff1a8 Signed-off-by: José Bollo --- expr.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/expr.c b/expr.c index 4059a32..3220509 100644 --- a/expr.c +++ b/expr.c @@ -229,21 +229,25 @@ expr_clone(struct expr_node *retp, const struct expr_node *node) node->u.call.own_rhs) < 0) return -1; retp->u.call.rhs = nrhs; - /* Fall through. */ - case EXPR_OP_UP: - case EXPR_OP_CALL1: if (expr_alloc_and_clone(&nlhs, node->lhs, node->own_lhs) < 0) { - if (node->kind == EXPR_OP_CALL2 - && node->u.call.own_rhs) { + if (node->u.call.own_rhs) { expr_destroy(nrhs); free(nrhs); - return -1; } + return -1; } retp->lhs = nlhs; return 0; + + case EXPR_OP_UP: + case EXPR_OP_CALL1: + if (expr_alloc_and_clone(&nlhs, node->lhs, node->own_lhs) < 0) + return -1; + + retp->lhs = nlhs; + return 0; } assert(!"Invalid value of node kind"); -- 2.7.4