susumu.yata
null+****@clear*****
Tue Nov 17 14:12:37 JST 2015
susumu.yata 2015-11-17 14:12:37 +0900 (Tue, 17 Nov 2015) New Revision: 262e8af6316ab59530ca3f136b77d8b8dd11652f https://github.com/groonga/groonga/commit/262e8af6316ab59530ca3f136b77d8b8dd11652f Message: grn_ts: do dereference in grn_ts_expr_op_node_open() Modified files: lib/ts/ts_expr_builder.c lib/ts/ts_expr_node.c lib/ts/ts_expr_node.h Modified: lib/ts/ts_expr_builder.c (+0 -10) =================================================================== --- lib/ts/ts_expr_builder.c 2015-11-17 13:28:52 +0900 (1f0b521) +++ lib/ts/ts_expr_builder.c 2015-11-17 14:12:37 +0900 (b5ec49d) @@ -643,16 +643,6 @@ grn_ts_expr_builder_push_op(grn_ctx *ctx, grn_ts_expr_builder *builder, } /* Arguments are the top n_args nodes in the stack. */ args = &builder->nodes[builder->n_nodes - n_args]; - for (i = 0; i < n_args; i++) { - /* - * FIXME: Operators "==" and "!=" should compare arguments as references - * if possible. - */ - rc = grn_ts_expr_node_deref(ctx, args[i], &args[i]); - if (rc != GRN_SUCCESS) { - return rc; - } - } builder->n_nodes -= n_args; rc = grn_ts_expr_op_node_open(ctx, op_type, args, n_args, &node); if (rc == GRN_SUCCESS) { Modified: lib/ts/ts_expr_node.c (+32 -12) =================================================================== --- lib/ts/ts_expr_node.c 2015-11-17 13:28:52 +0900 (5392d99) +++ lib/ts/ts_expr_node.c 2015-11-17 14:12:37 +0900 (afb6184) @@ -3102,6 +3102,37 @@ grn_ts_expr_op_node_check_args(grn_ctx *ctx, grn_ts_expr_op_node *node) } } +/* grn_ts_expr_op_node_setup() sets up an operator node. */ +static grn_rc +grn_ts_expr_op_node_setup(grn_ctx *ctx, grn_ts_expr_op_node *node) +{ + size_t i; + grn_rc rc; + for (i = 0; i < node->n_args; i++) { + /* + * FIXME: Operators "==" and "!=" should compare arguments as references + * if possible. + */ + rc = grn_ts_expr_node_deref(ctx, node->args[i], &node->args[i]); + if (rc != GRN_SUCCESS) { + return rc; + } + } + /* Check arguments. */ + rc = grn_ts_expr_op_node_check_args(ctx, node); + if (rc != GRN_SUCCESS) { + return rc; + } + if (node->data_kind == GRN_TS_VOID) { + GRN_TS_ERR_RETURN(GRN_OBJECT_CORRUPT, "invalid data kind: %d", + GRN_TS_VOID); + } else if (node->data_type == GRN_DB_VOID) { + GRN_TS_ERR_RETURN(GRN_OBJECT_CORRUPT, "invalid data type: %d", + GRN_DB_VOID); + } + return GRN_SUCCESS; +} + grn_rc grn_ts_expr_op_node_open(grn_ctx *ctx, grn_ts_op_type op_type, grn_ts_expr_node **args, size_t n_args, @@ -3124,18 +3155,7 @@ grn_ts_expr_op_node_open(grn_ctx *ctx, grn_ts_op_type op_type, new_node->args[i] = args[i]; } new_node->n_args = n_args; - - /* Check arguments. */ - rc = grn_ts_expr_op_node_check_args(ctx, new_node); - if (rc == GRN_SUCCESS) { - if (new_node->data_kind == GRN_TS_VOID) { - GRN_TS_ERR(GRN_OBJECT_CORRUPT, "invalid data kind: %d", GRN_TS_VOID); - rc = ctx->rc; - } else if (new_node->data_type == GRN_DB_VOID) { - GRN_TS_ERR(GRN_OBJECT_CORRUPT, "invalid data type: %d", GRN_DB_VOID); - rc = ctx->rc; - } - } + rc = grn_ts_expr_op_node_setup(ctx, new_node); if (rc != GRN_SUCCESS) { grn_ts_expr_op_node_fin(ctx, new_node); GRN_FREE(new_node); Modified: lib/ts/ts_expr_node.h (+4 -1) =================================================================== --- lib/ts/ts_expr_node.h 2015-11-17 13:28:52 +0900 (32a3d90) +++ lib/ts/ts_expr_node.h 2015-11-17 14:12:37 +0900 (56fbe48) @@ -78,7 +78,10 @@ grn_rc grn_ts_expr_const_node_open(grn_ctx *ctx, grn_ts_data_kind data_kind, grn_rc grn_ts_expr_column_node_open(grn_ctx *ctx, grn_obj *column, grn_ts_expr_node **node); -/* grn_ts_expr_op_node_open() creates a node associated with an operator. */ +/* + * grn_ts_expr_op_node_open() creates a node associated with an operator. + * Note that argument nodes are destroyed on failure. + */ grn_rc grn_ts_expr_op_node_open(grn_ctx *ctx, grn_ts_op_type op_type, grn_ts_expr_node **args, size_t n_args, grn_ts_expr_node **node); -------------- next part -------------- HTML����������������������������...다운로드