Fixed #4015 (segmentation fault of cppcheck (enum))

This commit is contained in:
Daniel Marjamäki 2012-08-06 16:21:21 +02:00
parent 445fd4e6aa
commit 5ee7758a83
2 changed files with 8 additions and 0 deletions

View File

@ -6889,6 +6889,8 @@ public:
else {
bool islast = (tok == end);
Token *last = Tokenizer::copyTokens(tok, other.start, other.end);
if (last == tok->next()) // tok->deleteThis() invalidates a pointer that points at the next token
last = tok;
tok->deleteThis();
if (islast) {
end = last;

View File

@ -350,6 +350,7 @@ private:
TEST_CASE(enum30); // ticket #3852 (false positive)
TEST_CASE(enum31); // ticket #3934 (calculation in first item)
TEST_CASE(enum32); // ticket #3998 (access violation)
TEST_CASE(enum33); // ticket #4015 (segmentation fault)
// remove "std::" on some standard functions
TEST_CASE(removestd);
@ -7048,6 +7049,11 @@ private:
ASSERT_EQUALS("{ a , ( 32 ) + 1 }", checkSimplifyEnum(code));
}
void enum33() { // #4015 - segmentation fault
const char code[] = "enum { A=SOME_VALUE, B=A };";
ASSERT_EQUALS(";", checkSimplifyEnum(code));
}
void removestd() {
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));
ASSERT_EQUALS("; strcat ( a , b ) ;", tok("; std::strcat(a,b);"));