From 6f966347599a2e8e5016f9665fa3b159782193cb Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Sun, 3 May 2015 15:21:58 +0200 Subject: [PATCH] #6276 clang: -fsanitize=integer warnings. Fix unwanted integer overflow in TemplateSimplifier::useDefaultArgumentValues() and Tokenizer::simplifyQtSignalsSlots() --- lib/templatesimplifier.cpp | 7 ++++--- lib/tokenize.cpp | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index a0c91242f..7b4b1e3e4 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -569,9 +569,10 @@ void TemplateSimplifier::useDefaultArgumentValues(const std::list &temp if (tok->str() == ">") { if (Token::Match(tok, "> class|struct %name%")) classname = tok->strAt(2); - --templateParmDepth; - if (0 == templateParmDepth) + if (templateParmDepth<2) break; + else + --templateParmDepth; } // next template parameter @@ -601,7 +602,7 @@ void TemplateSimplifier::useDefaultArgumentValues(const std::list &temp // count the parameters.. tok = tok->next(); - unsigned int usedpar = TemplateSimplifier::templateParameters(tok); + const unsigned int usedpar = TemplateSimplifier::templateParameters(tok); tok = tok->findClosingBracket(); if (tok && tok->str() == ">") { diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 913209890..38c4ca573 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9860,9 +9860,10 @@ void Tokenizer::simplifyQtSignalsSlots() else tok2 = tok2->link(); } else if (tok2->str() == "}") { - --indentlevel; - if (indentlevel == 0) + if (indentlevel<2) break; + else + --indentlevel; } if (tok2->strAt(1) == "Q_OBJECT") {