Fixed #3935 (False report for accessing array out of bounds after casting to short)
This commit is contained in:
parent
3656366c7e
commit
6a37942431
|
@ -4521,6 +4521,12 @@ void Tokenizer::simplifyCasts()
|
||||||
tok = tok->linkAt(2);
|
tok = tok->linkAt(2);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// #3935 : don't remove cast in such cases:
|
||||||
|
// ((char *)a)[1] = 0;
|
||||||
|
if (tok->str() == "(" && Token::simpleMatch(tok->link(), ") [")) {
|
||||||
|
tok = tok->link();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// #4164 : ((unsigned char)1) => (1)
|
// #4164 : ((unsigned char)1) => (1)
|
||||||
if (Token::Match(tok->next(), "( unsigned| %type% ) %num%") && tok->next()->link()->previous()->isStandardType()) {
|
if (Token::Match(tok->next(), "( unsigned| %type% ) %num%") && tok->next()->link()->previous()->isStandardType()) {
|
||||||
const MathLib::bigint value = MathLib::toLongNumber(tok->next()->link()->next()->str());
|
const MathLib::bigint value = MathLib::toLongNumber(tok->next()->link()->next()->str());
|
||||||
|
|
|
@ -84,6 +84,7 @@ private:
|
||||||
TEST_CASE(removeCast9);
|
TEST_CASE(removeCast9);
|
||||||
TEST_CASE(removeCast10);
|
TEST_CASE(removeCast10);
|
||||||
TEST_CASE(removeCast11);
|
TEST_CASE(removeCast11);
|
||||||
|
TEST_CASE(removeCast12);
|
||||||
|
|
||||||
TEST_CASE(inlineasm);
|
TEST_CASE(inlineasm);
|
||||||
|
|
||||||
|
@ -832,6 +833,11 @@ private:
|
||||||
ASSERT_EQUALS("; x = 0 ;", tokenizeAndStringify("; *(int *)&x = 0;", true));
|
ASSERT_EQUALS("; x = 0 ;", tokenizeAndStringify("; *(int *)&x = 0;", true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void removeCast12() {
|
||||||
|
// #3935 - don't remove this cast
|
||||||
|
ASSERT_EQUALS("; ( ( short * ) data ) [ 5 ] = 0 ;", tokenizeAndStringify("; ((short*)data)[5] = 0;", true));
|
||||||
|
}
|
||||||
|
|
||||||
void inlineasm() {
|
void inlineasm() {
|
||||||
ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("asm { mov ax,bx };"));
|
ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("asm { mov ax,bx };"));
|
||||||
ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("_asm { mov ax,bx };"));
|
ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("_asm { mov ax,bx };"));
|
||||||
|
|
Loading…
Reference in New Issue