Fixed #3998 (Tokenizer::simplifyEnum: wrong handling of expressions => crash)
This commit is contained in:
parent
87eb2d444c
commit
1a6f7ea9a0
|
@ -7048,7 +7048,7 @@ void Tokenizer::simplifyEnum()
|
||||||
// value is previous expression + 1
|
// value is previous expression + 1
|
||||||
tok1->insertToken("+");
|
tok1->insertToken("+");
|
||||||
tok1 = tok1->next();
|
tok1 = tok1->next();
|
||||||
tok1->insertToken(MathLib::toString<MathLib::bigint>(lastValue));
|
tok1->insertToken("1");
|
||||||
enumValue = 0;
|
enumValue = 0;
|
||||||
enumValueStart = valueStart->next();
|
enumValueStart = valueStart->next();
|
||||||
enumValueEnd = tok1->next();
|
enumValueEnd = tok1->next();
|
||||||
|
@ -7072,19 +7072,10 @@ void Tokenizer::simplifyEnum()
|
||||||
enumValueStart = tok1;
|
enumValueStart = tok1;
|
||||||
enumValueEnd = tok1;
|
enumValueEnd = tok1;
|
||||||
int level = 0;
|
int level = 0;
|
||||||
if (enumValueEnd->str() == "(" ||
|
while (enumValueEnd->next() && (!Token::Match(enumValueEnd->next(), "[},]") || level)) {
|
||||||
enumValueEnd->str() == "[" ||
|
if (Token::Match(enumValueEnd, "(|["))
|
||||||
enumValueEnd->str() == "{")
|
|
||||||
++level;
|
++level;
|
||||||
while (enumValueEnd->next() &&
|
else if (Token::Match(enumValueEnd->next(), "]|)"))
|
||||||
(!Token::Match(enumValueEnd->next(), "}|,") || level)) {
|
|
||||||
if (enumValueEnd->next()->str() == "(" ||
|
|
||||||
enumValueEnd->next()->str() == "[" ||
|
|
||||||
enumValueEnd->next()->str() == "{")
|
|
||||||
++level;
|
|
||||||
else if (enumValueEnd->next()->str() == ")" ||
|
|
||||||
enumValueEnd->next()->str() == "]" ||
|
|
||||||
enumValueEnd->next()->str() == "}")
|
|
||||||
--level;
|
--level;
|
||||||
|
|
||||||
enumValueEnd = enumValueEnd->next();
|
enumValueEnd = enumValueEnd->next();
|
||||||
|
@ -7101,11 +7092,11 @@ void Tokenizer::simplifyEnum()
|
||||||
EnumValue ev(enumName, enumValue, enumValueStart, enumValueEnd);
|
EnumValue ev(enumName, enumValue, enumValueStart, enumValueEnd);
|
||||||
ev.simplify(enumValues);
|
ev.simplify(enumValues);
|
||||||
enumValues[enumName->str()] = ev;
|
enumValues[enumName->str()] = ev;
|
||||||
if (ev.start == NULL) {
|
lastEnumValueStart = ev.start;
|
||||||
tok1 = ev.value;
|
lastEnumValueEnd = ev.end;
|
||||||
lastEnumValueStart = lastEnumValueEnd = NULL;
|
if (ev.start == NULL)
|
||||||
lastValue = MathLib::toLongNumber(ev.value->str());
|
lastValue = MathLib::toLongNumber(ev.value->str());
|
||||||
}
|
tok1 = ev.end ? ev.end : ev.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -348,6 +348,7 @@ private:
|
||||||
TEST_CASE(enum29); // ticket #3747 (bitwise or value)
|
TEST_CASE(enum29); // ticket #3747 (bitwise or value)
|
||||||
TEST_CASE(enum30); // ticket #3852 (false positive)
|
TEST_CASE(enum30); // ticket #3852 (false positive)
|
||||||
TEST_CASE(enum31); // ticket #3934 (calculation in first item)
|
TEST_CASE(enum31); // ticket #3934 (calculation in first item)
|
||||||
|
TEST_CASE(enum32); // ticket #3998 (access violation)
|
||||||
|
|
||||||
// remove "std::" on some standard functions
|
// remove "std::" on some standard functions
|
||||||
TEST_CASE(removestd);
|
TEST_CASE(removestd);
|
||||||
|
@ -6702,7 +6703,7 @@ private:
|
||||||
"1 + sizeof ( int ) + "
|
"1 + sizeof ( int ) + "
|
||||||
"1 + sizeof ( int ) + 100 + "
|
"1 + sizeof ( int ) + 100 + "
|
||||||
"1 + sizeof ( int ) + 100 + 1 + "
|
"1 + sizeof ( int ) + 100 + 1 + "
|
||||||
"1 + sizeof ( int ) + 100 + 2 + "
|
"1 + sizeof ( int ) + 100 + 1 + 1 + "
|
||||||
"90 + "
|
"90 + "
|
||||||
"91 ;";
|
"91 ;";
|
||||||
|
|
||||||
|
@ -7033,6 +7034,11 @@ private:
|
||||||
ASSERT_EQUALS("i = 65 ;", checkSimplifyEnum(code));
|
ASSERT_EQUALS("i = 65 ;", checkSimplifyEnum(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void enum32() { // #3998 - wrong enum simplification => access violation
|
||||||
|
const char code[] = "enum { x=(32), y=x, z }; { a, z }";
|
||||||
|
ASSERT_EQUALS("{ a , ( 32 ) + 1 }", checkSimplifyEnum(code));
|
||||||
|
}
|
||||||
|
|
||||||
void removestd() {
|
void removestd() {
|
||||||
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));
|
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));
|
||||||
ASSERT_EQUALS("; strcat ( a , b ) ;", tok("; std::strcat(a,b);"));
|
ASSERT_EQUALS("; strcat ( a , b ) ;", tok("; std::strcat(a,b);"));
|
||||||
|
|
Loading…
Reference in New Issue