Skip to content

Commit d3685bc

Browse files
committed
fix: get correct substring for cond RHS var/cvar parsing
Also fix some minor UB in the error case of cond parsing. Resolves: #132
1 parent 0235f5a commit d3685bc

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

src/Features/ConfigPlus.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -590,14 +590,13 @@ static Condition *ParseCondition(std::queue<Token> toks) {
590590

591591
toks.pop();
592592

593-
Token val_tok = toks.front();
594-
595-
if (toks.empty() || val_tok.type != TOK_STR) {
593+
if (toks.empty() || toks.front().type != TOK_STR) {
596594
console->Print("Expected string token after '%.*s='\n", t.len, t.str);
597595
CLEAR_OUT_STACK;
598596
return NULL;
599597
}
600598

599+
Token val_tok = toks.front();
601600
toks.pop();
602601

603602
if (!strncmp(t.str, "var:", 4) || t.str[0] == '?') {
@@ -623,11 +622,11 @@ static Condition *ParseCondition(std::queue<Token> toks) {
623622

624623
if (val_tok.len > 4 && !strncmp(val_tok.str, "var:", 4) || val_tok.len > 1 && val_tok.str[0] == '?') {
625624
int i = val_tok.str[0] == 'v' ? 4 : 1;
626-
auto val = GetSvar({val_tok.str + i});
625+
auto val = GetSvar(std::string(val_tok.str + i, val_tok.len - i));
627626
c->val = strdup(val.c_str());
628627
} else if (val_tok.len > 5 && !strncmp(val_tok.str, "cvar:", 5) || val_tok.len > 1 && val_tok.str[0] == '#') {
629628
int i = val_tok.str[0] == 'c' ? 5 : 1;
630-
auto val = GetCvar({val_tok.str + i});
629+
auto val = GetCvar(std::string(val_tok.str + i, val_tok.len - i));
631630
c->val = strdup(val.c_str());
632631
} else {
633632
c->val = (char *)malloc(val_tok.len + 1);

0 commit comments

Comments
 (0)