From 722e33e4e698c1fa4d93d3f34e9460162aa21d49 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 27 Feb 2015 19:22:35 +0100 Subject: [PATCH] analyzer: Verify the type of arithmetic operands. --- src/frontend/analyzer.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/frontend/analyzer.c b/src/frontend/analyzer.c index 607015c..75aa94d 100644 --- a/src/frontend/analyzer.c +++ b/src/frontend/analyzer.c @@ -68,6 +68,14 @@ cmp_error(sdb_strbuf_t *errbuf, int op, int left, int right) SDB_TYPE_TO_STRING(right)); } /* cmp_error */ +static void +op_error(sdb_strbuf_t *errbuf, int op, int left, int right) +{ + sdb_strbuf_sprintf(errbuf, "Invalid operator %s for types %s and %s", + SDB_DATA_OP_TO_STRING(op), SDB_TYPE_TO_STRING(left), + SDB_TYPE_TO_STRING(right)); +} /* cmp_error */ + static int analyze_expr(int context, sdb_store_expr_t *e, sdb_strbuf_t *errbuf) { @@ -104,6 +112,15 @@ analyze_expr(int context, sdb_store_expr_t *e, sdb_strbuf_t *errbuf) return -1; if (analyze_expr(context, e->right, errbuf)) return -1; + + if ((e->left->data_type > 0) && (e->right->data_type > 0)) { + if (sdb_data_expr_type(e->type, e->left->data_type, + e->right->data_type) < 0) { + op_error(errbuf, e->type, e->left->data_type, + e->right->data_type); + return -1; + } + } break; } return 0; -- 2.30.2