Fixed calculation of array size (#6487)
This commit is contained in:
parent
ae4b86c231
commit
1f97e3001b
|
@ -2050,8 +2050,8 @@ void Tokenizer::simplifyDoublePlusAndDoubleMinus()
|
||||||
|
|
||||||
void Tokenizer::arraySize()
|
void Tokenizer::arraySize()
|
||||||
{
|
{
|
||||||
bool addlength = false;
|
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
|
bool addlength = false;
|
||||||
if (Token::Match(tok, "%name% [ ] = { %str% } ;")) {
|
if (Token::Match(tok, "%name% [ ] = { %str% } ;")) {
|
||||||
Token *t = tok->tokAt(3);
|
Token *t = tok->tokAt(3);
|
||||||
t->deleteNext();
|
t->deleteNext();
|
||||||
|
@ -2061,9 +2061,8 @@ void Tokenizer::arraySize()
|
||||||
|
|
||||||
if (addlength || Token::Match(tok, "%name% [ ] = %str% ;")) {
|
if (addlength || Token::Match(tok, "%name% [ ] = %str% ;")) {
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
std::size_t sz = tok->strAt(3).length() - 1;
|
std::size_t sz = Token::getStrSize(tok->tokAt(3));
|
||||||
tok->insertToken(MathLib::toString((unsigned int)sz));
|
tok->insertToken(MathLib::toString((unsigned int)sz));
|
||||||
addlength = false;
|
|
||||||
tok = tok->tokAt(5);
|
tok = tok->tokAt(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -717,6 +717,10 @@ private:
|
||||||
const char code3[] = "char str [ ] = \"\\0\";";
|
const char code3[] = "char str [ ] = \"\\0\";";
|
||||||
const char expected3[] = "char str [ 2 ] = \"\\0\" ;";
|
const char expected3[] = "char str [ 2 ] = \"\\0\" ;";
|
||||||
ASSERT_EQUALS(expected3, tok(code3));
|
ASSERT_EQUALS(expected3, tok(code3));
|
||||||
|
|
||||||
|
const char code4[] = "char str [ ] = \"\\n\\n\";";
|
||||||
|
const char expected4[] = "char str [ 3 ] = \"\\n\\n\" ;";
|
||||||
|
ASSERT_EQUALS(expected4, tok(code4));
|
||||||
}
|
}
|
||||||
|
|
||||||
void dontRemoveIncrement() {
|
void dontRemoveIncrement() {
|
||||||
|
|
Loading…
Reference in New Issue