From 99d8ce37320ded057d5c3e73225de4dcdeb4aded Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Mon, 12 Dec 2011 02:23:49 +0100 Subject: [PATCH] Fix Valgrind error in arraySize(): if there's code like: 'int [ ] a = { 1 , 5 , }', 'end' is last '}', when 'tok2' arrives to second ',' and cppcheck finds out that next token to 'tok2' is '}', remove this ',' with 'tok2->deleteThis()' but it causes (maybe) a memory corruption to 'end' which will gave problems later because 'tok' will be assigned to it or its next token. --- lib/tokenize.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index aa86cd5ff..7bac0e42c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2618,8 +2618,10 @@ void Tokenizer::arraySize() } else if (tok2->str() == ",") { if (!Token::Match(tok2->next(), "[},]")) ++sz; - else - tok2->deleteThis(); + else { + tok2 = tok2->previous(); + tok2->deleteNext(); + } } }