Small refactorizations:
- #include cleanup - Use std::array instead of std::vector - Do not create a stringstream to concatenate 4 strings - Use std::cout instead of printf
This commit is contained in:
parent
e8decd925b
commit
e8522c7883
|
@ -26,7 +26,6 @@
|
|||
#include "threadexecutor.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <climits>
|
||||
#include <cstdlib> // EXIT_SUCCESS and EXIT_FAILURE
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "pathmatch.h"
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -114,7 +113,7 @@ void FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, co
|
|||
continue;
|
||||
|
||||
const char* ansiFfd = ffd.cFileName;
|
||||
if (strchr(ansiFfd,'?')) {
|
||||
if (std::strchr(ansiFfd,'?')) {
|
||||
ansiFfd = ffd.cAlternateFileName;
|
||||
}
|
||||
|
||||
|
@ -122,9 +121,9 @@ void FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, co
|
|||
|
||||
if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
|
||||
// File
|
||||
if ((!checkAllFilesInDir || Path::acceptFile(fname, extra)) && !ignored.Match(fname)) {
|
||||
const std::string nativename = Path::fromNativeSeparators(fname);
|
||||
|
||||
if ((!checkAllFilesInDir || Path::acceptFile(fname, extra)) && !ignored.Match(fname)) {
|
||||
// Limitation: file sizes are assumed to fit in a 'size_t'
|
||||
#ifdef _WIN64
|
||||
files[nativename] = (static_cast<std::size_t>(ffd.nFileSizeHigh) << 32) | ffd.nFileSizeLow;
|
||||
|
@ -168,6 +167,7 @@ bool FileLister::fileExists(const std::string &path)
|
|||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sstream>
|
||||
|
||||
// Get absolute path. Returns empty string if path does not exist or other error.
|
||||
std::string FileLister::getAbsolutePath(const std::string& path)
|
||||
|
|
|
@ -102,7 +102,7 @@ void CheckOther::checkZeroDivision()
|
|||
|
||||
#include "cppcheckexecutor.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -136,11 +136,11 @@ int main(int argc, char* argv[])
|
|||
return exec.check(argc, argv);
|
||||
#ifdef NDEBUG
|
||||
} catch (const InternalError& e) {
|
||||
printf("%s\n", e.errorMessage.c_str());
|
||||
std::cout << e.errorMessage << std::endl;
|
||||
} catch (const std::exception& error) {
|
||||
printf("%s\n", error.what());
|
||||
std::cout << error.what() << std::endl;
|
||||
} catch (...) {
|
||||
printf("Unknown exception\n");
|
||||
std::cout << "Unknown exception" << std::endl;
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
#endif
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
*/
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// 64-bit portability
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include "check.h"
|
||||
|
||||
|
|
|
@ -75,9 +75,6 @@ public:
|
|||
/** @brief negative size for array */
|
||||
void negativeArraySize();
|
||||
|
||||
/** @brief %Check for buffer overruns by inspecting execution paths */
|
||||
void executionPaths();
|
||||
|
||||
/**
|
||||
* @brief Get minimum length of format string result
|
||||
* @param input_string format string
|
||||
|
|
|
@ -23,10 +23,10 @@
|
|||
#include "token.h"
|
||||
#include "errorlogger.h"
|
||||
#include "symboldatabase.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include <string>
|
||||
#include <set>
|
||||
#include <cstring>
|
||||
#include <cctype>
|
||||
|
||||
// Register this check class (by creating a static instance of it).
|
||||
// Disabled in release builds
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "tokenize.h"
|
||||
#include "symboldatabase.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
#include "mathlib.h"
|
||||
#include "tokenize.h"
|
||||
#include "astutils.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <set>
|
||||
#include <stack>
|
||||
|
||||
|
@ -2060,12 +2060,9 @@ void CheckMemoryLeakInFunction::checkScope(const Token *startTok, const std::str
|
|||
noerr = noerr || Token::simpleMatch(first, "alloc ; if return ; dealloc; }");
|
||||
|
||||
// Unhandled case..
|
||||
if (!noerr) {
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "inconclusive leak of " << varname << ": ";
|
||||
errmsg << tok->stringifyList(false, false, false, false, false, 0, 0);
|
||||
reportError(first, Severity::debug, "debug", errmsg.str());
|
||||
}
|
||||
if (!noerr)
|
||||
reportError(first, Severity::debug, "debug",
|
||||
"inconclusive leak of " + varname + ": " + tok->stringifyList(false, false, false, false, false, 0, 0));
|
||||
}
|
||||
|
||||
TokenList::deleteTokens(tok);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "checknullpointer.h"
|
||||
#include "mathlib.h"
|
||||
#include "symboldatabase.h"
|
||||
#include "utils.h"
|
||||
#include <cctype>
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
#include "astutils.h"
|
||||
#include "mathlib.h"
|
||||
#include "symboldatabase.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <cmath> // fabs()
|
||||
#include <stack>
|
||||
#include <algorithm> // find_if()
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "checkstl.h"
|
||||
#include "symboldatabase.h"
|
||||
#include "checknullpointer.h"
|
||||
#include "utils.h"
|
||||
#include <sstream>
|
||||
|
||||
// Register this check class (by creating a static instance of it)
|
||||
|
@ -1476,7 +1477,7 @@ void CheckStl::readingEmptyStlContainer()
|
|||
bool insert = false;
|
||||
if (var->nameToken() == tok && var->isLocal() && !var->isStatic()) { // Local variable declared
|
||||
insert = !Token::Match(tok->tokAt(1), "[(=]"); // Only if not initialized
|
||||
} else if (Token::Match(tok, "%name% . clear ( ) ;")) {
|
||||
} else if (Token::Match(tok, "%var% . clear ( ) ;")) {
|
||||
insert = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,9 +21,8 @@
|
|||
#include "checkuninitvar.h"
|
||||
#include "astutils.h"
|
||||
#include "mathlib.h"
|
||||
#include "checknullpointer.h" // CheckNullPointer::parseFunctionCall
|
||||
#include "checknullpointer.h" // CheckNullPointer::isPointerDeref
|
||||
#include "symboldatabase.h"
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <cassert>
|
||||
#include <stack>
|
||||
|
@ -172,10 +171,9 @@ void CheckUninitVar::checkStruct(const Token *tok, const Variable &structvar)
|
|||
}
|
||||
|
||||
struct VariableValue {
|
||||
VariableValue() : notEqual(false), value(0) {}
|
||||
explicit VariableValue(MathLib::bigint val) : notEqual(false), value(val) {}
|
||||
bool notEqual;
|
||||
explicit VariableValue(MathLib::bigint val = 0) : value(val), notEqual(false) {}
|
||||
MathLib::bigint value;
|
||||
bool notEqual;
|
||||
};
|
||||
static VariableValue operator!(VariableValue v)
|
||||
{
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "checkunusedvar.h"
|
||||
#include "symboldatabase.h"
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <utility>
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <cassert>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
InternalError::InternalError(const Token *tok, const std::string &errorMsg, Type type) :
|
||||
token(tok), errorMessage(errorMsg)
|
||||
|
@ -131,7 +131,8 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
|
|||
_inconclusive = false;
|
||||
_callStack.clear();
|
||||
std::istringstream iss(data);
|
||||
std::vector<std::string> results;
|
||||
std::array<std::string, 5> results;
|
||||
std::size_t elem = 0;
|
||||
while (iss.good()) {
|
||||
unsigned int len = 0;
|
||||
if (!(iss >> len))
|
||||
|
@ -149,12 +150,12 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
|
|||
continue;
|
||||
}
|
||||
|
||||
results.push_back(temp);
|
||||
if (results.size() == 5)
|
||||
results[elem++] = temp;
|
||||
if (elem == 5)
|
||||
break;
|
||||
}
|
||||
|
||||
if (results.size() != 5)
|
||||
if (elem != 5)
|
||||
throw InternalError(0, "Internal Error: Deserialization of error message failed");
|
||||
|
||||
_id = results[0];
|
||||
|
|
|
@ -21,12 +21,12 @@
|
|||
#define errorloggerH
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#include "config.h"
|
||||
#include "suppressions.h"
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
class Token;
|
||||
class TokenList;
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include "astutils.h"
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
static std::vector<std::string> getnames(const char *names)
|
||||
{
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
#include "config.h"
|
||||
#include "mathlib.h"
|
||||
#include "token.h"
|
||||
#include "standards.h"
|
||||
#include "errorlogger.h"
|
||||
|
||||
|
@ -31,8 +30,8 @@
|
|||
#include <set>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
class TokenList;
|
||||
namespace tinyxml2 {
|
||||
class XMLDocument;
|
||||
class XMLElement;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <cmath>
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
#include <limits>
|
||||
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#define mathlibH
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "config.h"
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
*/
|
||||
|
||||
#include "settings.h"
|
||||
#include "path.h"
|
||||
#include "preprocessor.h" // Preprocessor
|
||||
#include "utils.h"
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
*/
|
||||
|
||||
#include "suppressions.h"
|
||||
#include "settings.h"
|
||||
#include "path.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "token.h"
|
||||
#include "settings.h"
|
||||
#include "errorlogger.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include "config.h"
|
||||
#include "token.h"
|
||||
#include "mathlib.h"
|
||||
#include "utils.h"
|
||||
|
||||
class Tokenizer;
|
||||
class Settings;
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
|
||||
#include "token.h"
|
||||
#include "errorlogger.h"
|
||||
#include "check.h"
|
||||
#include "settings.h"
|
||||
#include "symboldatabase.h"
|
||||
#include "utils.h"
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
#include "tokenize.h"
|
||||
#include "mathlib.h"
|
||||
|
@ -26,6 +25,7 @@
|
|||
#include "symboldatabase.h"
|
||||
#include "templatesimplifier.h"
|
||||
#include "timer.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include <sstream>
|
||||
#include <cctype>
|
||||
#include <stack>
|
||||
#include <cassert>
|
||||
|
||||
// How many compileExpression recursions are allowed?
|
||||
// For practical code this could be endless. But in some special torture test
|
||||
|
|
|
@ -19,9 +19,8 @@
|
|||
#include "testsuite.h"
|
||||
#include "preprocessor.h"
|
||||
#include "options.h"
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -41,11 +40,11 @@ int main(int argc, char *argv[])
|
|||
return (failedTestsCount == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
#ifdef NDEBUG
|
||||
} catch (const InternalError& e) {
|
||||
printf("%s\n", e.errorMessage.c_str());
|
||||
std::cout << e.errorMessage << std::endl;
|
||||
} catch (const std::exception& error) {
|
||||
printf("%s\n", error.what());
|
||||
std::cout << error.what() << std::endl;
|
||||
} catch (...) {
|
||||
printf("Unknown exception\n");
|
||||
std::cout << "Unknown exception" << std::endl;
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
#endif
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "cppcheckexecutor.h"
|
||||
#include "path.h"
|
||||
#include "pathmatch.h"
|
||||
#include "redirect.h"
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
|
||||
#include "testsuite.h"
|
||||
#include "options.h"
|
||||
#include "redirect.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <list>
|
||||
|
||||
std::ostringstream errout;
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include <sstream>
|
||||
#include <set>
|
||||
#include "errorlogger.h"
|
||||
#include "redirect.h"
|
||||
|
||||
class options;
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "testsuite.h"
|
||||
#include "testutils.h"
|
||||
#include "symboldatabase.h"
|
||||
#include "utils.h"
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
|
|
Loading…
Reference in New Issue