struct ec_tk_seq *tk = (struct ec_tk_seq *)gen_tk;
struct ec_parsed_tk *parsed_tk, *child_parsed_tk;
struct ec_strvec *match_strvec;
- struct ec_strvec childvec;
+ struct ec_strvec *childvec = NULL;
size_t len = 0;
unsigned int i;
goto fail;
for (i = 0; i < tk->len; i++) {
- if (ec_strvec_slice(&childvec, strvec, len) < 0)
+ childvec = ec_strvec_ndup(strvec, len,
+ ec_strvec_len(strvec) - len);
+ if (childvec == NULL)
goto fail;
- child_parsed_tk = ec_tk_parse_tokens(tk->table[i], &childvec);
+ child_parsed_tk = ec_tk_parse_tokens(tk->table[i], childvec);
if (child_parsed_tk == NULL)
goto fail;
+
+ ec_strvec_free(childvec);
+ childvec = NULL;
+
if (!ec_parsed_tk_matches(child_parsed_tk)) {
ec_parsed_tk_free(child_parsed_tk);
ec_parsed_tk_free_children(parsed_tk);
len += ec_parsed_tk_len(child_parsed_tk);
}
- match_strvec = ec_strvec_ndup(strvec, len);
+ match_strvec = ec_strvec_ndup(strvec, 0, len);
if (match_strvec == NULL)
goto fail;
return parsed_tk;
- fail:
+fail:
+ ec_strvec_free(childvec);
ec_parsed_tk_free(parsed_tk);
return NULL;
}
{
struct ec_tk_seq *tk = (struct ec_tk_seq *)gen_tk;
struct ec_completed_tk *completed_tk, *child_completed_tk;
- struct ec_strvec childvec;
+ struct ec_strvec *childvec = NULL;
struct ec_parsed_tk *parsed_tk;
size_t len = 0;
unsigned int i;
return completed_tk;
for (i = 0; i < tk->len && len < ec_strvec_len(strvec); i++) {
- if (ec_strvec_slice(&childvec, strvec, len) < 0)
+ childvec = ec_strvec_ndup(strvec, len,
+ ec_strvec_len(strvec) - len);
+ if (childvec == NULL)
goto fail;
child_completed_tk = ec_tk_complete_tokens(tk->table[i],
- &childvec);
- if (child_completed_tk == NULL) {
- ec_completed_tk_free(completed_tk);
- return NULL;
- }
+ childvec);
+ if (child_completed_tk == NULL)
+ goto fail;
+
ec_completed_tk_merge(completed_tk, child_completed_tk);
- parsed_tk = ec_tk_parse_tokens(tk->table[i], &childvec);
+ parsed_tk = ec_tk_parse_tokens(tk->table[i], childvec);
if (parsed_tk == NULL)
goto fail;
+
+ ec_strvec_free(childvec);
+ childvec = NULL;
+
if (!ec_parsed_tk_matches(parsed_tk)) {
ec_parsed_tk_free(parsed_tk);
break;
return completed_tk;
fail:
- /* XXX */
+ ec_strvec_free(childvec);
+ ec_completed_tk_free(completed_tk);
return NULL;
}
tk = (struct ec_tk_seq *)ec_tk_seq_new(id);
if (tk == NULL)
- goto fail;
+ fail = 1;
for (child = va_arg(ap, struct ec_tk *);
child != EC_TK_ENDLIST;
child = va_arg(ap, struct ec_tk *)) {
- /* on error, don't quit the loop to avoid leaks */
- if (child == NULL || ec_tk_seq_add(&tk->gen, child) < 0)
+ /* on error, don't quit the loop to avoid leaks */
+ if (fail == 1 || child == NULL ||
+ ec_tk_seq_add(&tk->gen, child) < 0) {
fail = 1;
+ ec_tk_free(child);
+ }
}
if (fail == 1)
tk->table = table;
table[tk->len] = child;
- tk->len ++;
+ tk->len++;
child->parent = gen_tk;
- TAILQ_INSERT_TAIL(&gen_tk->children, child, next);
+ TAILQ_INSERT_TAIL(&gen_tk->children, child, next); // XXX really needed?
return 0;
}