From 7692a306cddc99d43614e82cde82f19346184f7c Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Fri, 6 Jun 2014 18:58:20 +0400 Subject: [PATCH] Cleanup code - reorder checks and make variable declaration scope narrower. --- lib/checkbufferoverrun.cpp | 4 ++-- lib/tokenize.cpp | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 867d89801..7c978ff3e 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -281,10 +281,10 @@ static const Token *for_init(const Token *tok, unsigned int &varid, std::string varid = tok->varId(); varname = tok->str(); - tok = tok->tokAt(4); - if (varid == 0) return 0; // failed + + tok = tok->tokAt(4); } else if (Token::Match(tok, "%type% %var% = %any% ;")) { if (tok->tokAt(3)->isNumber()) { init_value = tok->strAt(3); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index af373f042..06077fb23 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8772,7 +8772,7 @@ std::string Tokenizer::simplifyString(const std::string &source) unsigned int sz = 0; // size of stringdata if (str[i+1] == 'x') { sz = 2; - while (std::isxdigit((unsigned char)str[i+sz]) && sz < 4) + while (sz < 4 && std::isxdigit((unsigned char)str[i+sz])) sz++; if (sz > 2) { std::istringstream istr(str.substr(i+2, sz-2)); @@ -8780,7 +8780,7 @@ std::string Tokenizer::simplifyString(const std::string &source) } } else if (MathLib::isOctalDigit(str[i+1])) { sz = 2; - while (MathLib::isOctalDigit(str[i+sz]) && sz < 4) + while (sz < 4 && MathLib::isOctalDigit(str[i+sz])) sz++; std::istringstream istr(str.substr(i+1, sz-1)); istr >> std::oct >> c; @@ -9012,7 +9012,6 @@ void Tokenizer::simplifyStructDecl() } for (Token *tok = list.front(); tok; tok = tok->next()) { - Token *restart; // check for start of scope and determine if it is in a function if (tok->str() == "{") @@ -9038,7 +9037,7 @@ void Tokenizer::simplifyStructDecl() tok = next->link(); if (!tok) break; // see #4869 segmentation fault in Tokenizer::simplifyStructDecl (invalid code) - restart = next; + Token *restart = next; // check for named type if (Token::Match(tok->next(), "*|&| %type% ,|;|[|=")) { @@ -9061,16 +9060,16 @@ void Tokenizer::simplifyStructDecl() // check for anonymous struct/union else if (Token::Match(tok, "struct|union {")) { - bool inFunction = skip.top(); + const bool inFunction = skip.top(); skip.push(false); Token *tok1 = tok; - restart = tok->next(); + Token *restart = tok->next(); tok = tok->next()->link(); // unnamed anonymous struct/union so possibly remove it if (tok && tok->next() && tok->next()->str() == ";") { - if (tok1->str() == "union" && inFunction) { + if (inFunction && tok1->str() == "union") { // Try to create references in the union.. Token *tok2 = tok1->tokAt(2); while (tok2) { @@ -9099,7 +9098,7 @@ void Tokenizer::simplifyStructDecl() } // don't remove unnamed anonymous unions from a class, struct or union - if (!(tok1->str() == "union" && !inFunction)) { + if (!(!inFunction && tok1->str() == "union")) { skip.pop(); tok1->deleteThis(); if (tok1->next() == tok) {