Parse IN [val, val, ...] list. Returns expr_leaf or NULL on error. */
| 905 | |
| 906 | /* Parse IN [val, val, ...] list. Returns expr_leaf or NULL on error. */ |
| 907 | static cbm_expr_t *parse_in_list(parser_t *p, cbm_condition_t *c) { |
| 908 | advance(p); |
| 909 | c->op = heap_strdup("IN"); |
| 910 | if (!c->op) { |
| 911 | safe_str_free(&c->variable); |
| 912 | safe_str_free(&c->property); |
| 913 | return NULL; |
| 914 | } |
| 915 | if (!expect(p, TOK_LBRACKET)) { |
| 916 | safe_str_free(&c->variable); |
| 917 | safe_str_free(&c->property); |
| 918 | safe_str_free(&c->op); |
| 919 | return NULL; |
| 920 | } |
| 921 | int vcap = CYP_INIT_CAP8; |
| 922 | int vn = 0; |
| 923 | const char **vals = malloc(vcap * sizeof(const char *)); |
| 924 | if (!vals) { |
| 925 | safe_str_free(&c->variable); |
| 926 | safe_str_free(&c->property); |
| 927 | safe_str_free(&c->op); |
| 928 | return NULL; |
| 929 | } |
| 930 | while (!check(p, TOK_RBRACKET) && !check(p, TOK_EOF)) { |
| 931 | if (vn > 0) { |
| 932 | match(p, TOK_COMMA); |
| 933 | } |
| 934 | if (check(p, TOK_STRING) || check(p, TOK_NUMBER)) { |
| 935 | if (vn >= vcap) { |
| 936 | int new_vcap = vcap * PAIR_LEN; |
| 937 | void *tmp = realloc((void *)vals, new_vcap * sizeof(const char *)); |
| 938 | if (!tmp) { |
| 939 | for (int i = 0; i < vn; i++) { |
| 940 | safe_str_free(&vals[i]); |
| 941 | } |
| 942 | safe_free(vals); |
| 943 | safe_str_free(&c->variable); |
| 944 | safe_str_free(&c->property); |
| 945 | safe_str_free(&c->op); |
| 946 | return NULL; |
| 947 | } |
| 948 | vals = (const char **)tmp; |
| 949 | vcap = new_vcap; |
| 950 | } |
| 951 | const char *new_val = heap_strdup(advance(p)->text); |
| 952 | if (!new_val) { |
| 953 | for (int i = 0; i < vn; i++) { |
| 954 | safe_str_free(&vals[i]); |
| 955 | } |
| 956 | safe_free(vals); |
| 957 | safe_str_free(&c->variable); |
| 958 | safe_str_free(&c->property); |
| 959 | safe_str_free(&c->op); |
| 960 | return NULL; |
| 961 | } |
| 962 | vals[vn++] = new_val; |
| 963 | } else { |
| 964 | break; |
no test coverage detected