Fixed #806 (cppcheck crashes scanning openssl)

This commit is contained in:
Daniel Marjamäki 2009-10-09 21:11:29 +02:00
parent dbfba8c2a6
commit 67f53661a9
2 changed files with 16 additions and 1 deletions

View File

@ -4291,8 +4291,11 @@ std::string Tokenizer::simplifyString(const std::string &source)
// We will replace all other character as 'a'
// If that causes problems in the future, this can
// be improved. But for now, this should be OK.
int n = 1;
while (n < 2 && std::isxdigit(str[i+1+n]))
++n;
--i;
str.replace(i, 4, "a");
str.replace(i, 2 + n, "a");
}
}
else if (MathLib::isOctalDigit(str[i]))

View File

@ -158,6 +158,8 @@ private:
TEST_CASE(removeExceptionSpecification);
TEST_CASE(gt); // use "<" comparisons instead of ">"
TEST_CASE(simplifyString);
}
@ -2542,6 +2544,16 @@ private:
ASSERT_EQUALS("; i < 10 ;", tokenizeAndStringify(";10>i;"));
}
void simplifyString()
{
Tokenizer *tokenizer = 0;
ASSERT_EQUALS("\"abc\"", tokenizer->simplifyString("\"abc\""));
ASSERT_EQUALS("\"a\"", tokenizer->simplifyString("\"\\x3\""));
ASSERT_EQUALS("\"a\"", tokenizer->simplifyString("\"\\x33\""));
ASSERT_EQUALS("\"a3\"", tokenizer->simplifyString("\"\\x333\""));
}
};
REGISTER_TEST(TestTokenizer)