Merge branch 'master' of https://github.com/danmar/cppcheck
This commit is contained in:
commit
227a73eb45
|
@ -118,8 +118,10 @@ void Token::update_property_isStandardType()
|
||||||
if (_str.size() < 3)
|
if (_str.size() < 3)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
static const char * const stdtype[] = { "bool", "char", "char16_t", "char32_t", "double", "float", "int", "long", "short", "size_t", "void", "wchar_t"};
|
static const std::set<std::string> stdTypes = make_container<std::set<std::string> >() <<
|
||||||
if (std::binary_search(stdtype, stdtype + sizeof(stdtype) / sizeof(stdtype[0]), _str)) {
|
"bool" << "char" << "char16_t" << "char32_t" << "double" << "float" << "int" << "long" << "short" << "size_t" << "void" << "wchar_t";
|
||||||
|
|
||||||
|
if (stdTypes.find(_str)!=stdTypes.end()) {
|
||||||
isStandardType(true);
|
isStandardType(true);
|
||||||
_type = eType;
|
_type = eType;
|
||||||
}
|
}
|
||||||
|
|
274
lib/tokenize.cpp
274
lib/tokenize.cpp
|
@ -9564,54 +9564,50 @@ void Tokenizer::simplifyNamespaceStd()
|
||||||
if (!isCPP())
|
if (!isCPP())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
static const char* stdTypes_[] = { // Types and objects in std namespace that are neither functions nor templates
|
// Types and objects in std namespace that are neither functions nor templates
|
||||||
"string", "wstring", "u16string", "u32string",
|
static const std::set<std::string> stdTypes = make_container<std::set<std::string> >() <<
|
||||||
"iostream", "ostream", "ofstream", "ostringstream",
|
"string"<< "wstring"<< "u16string"<< "u32string" <<
|
||||||
"istream", "ifstream", "istringstream", "fstream", "stringstream",
|
"iostream"<< "ostream"<< "ofstream"<< "ostringstream" <<
|
||||||
"wstringstream", "wistringstream", "wostringstream", "wstringbuf",
|
"istream"<< "ifstream"<< "istringstream"<< "fstream"<< "stringstream" <<
|
||||||
"stringbuf", "streambuf", "ios", "filebuf", "ios_base",
|
"wstringstream"<< "wistringstream"<< "wostringstream"<< "wstringbuf" <<
|
||||||
"exception", "bad_exception", "bad_alloc",
|
"stringbuf"<< "streambuf"<< "ios"<< "filebuf"<< "ios_base" <<
|
||||||
"logic_error", "domain_error", "invalid_argument_", "length_error",
|
"exception"<< "bad_exception"<< "bad_alloc" <<
|
||||||
"out_of_range", "runtime_error", "range_error", "overflow_error", "underflow_error",
|
"logic_error"<< "domain_error"<< "invalid_argument_"<< "length_error" <<
|
||||||
"locale",
|
"out_of_range"<< "runtime_error"<< "range_error"<< "overflow_error"<< "underflow_error" <<
|
||||||
"cout", "cerr", "clog", "cin",
|
"locale" <<
|
||||||
"wcerr", "wcin", "wclog", "wcout",
|
"cout"<< "cerr"<< "clog"<< "cin" <<
|
||||||
"endl", "ends", "flush",
|
"wcerr"<< "wcin"<< "wclog"<< "wcout" <<
|
||||||
"boolalpha", "noboolalpha", "showbase", "noshowbase",
|
"endl"<< "ends"<< "flush" <<
|
||||||
"showpoint", "noshowpoint", "showpos", "noshowpos",
|
"boolalpha"<< "noboolalpha"<< "showbase"<< "noshowbase" <<
|
||||||
"skipws", "noskipws", "unitbuf", "nounitbuf", "uppercase", "nouppercase",
|
"showpoint"<< "noshowpoint"<< "showpos"<< "noshowpos" <<
|
||||||
"dec", "hex", "oct",
|
"skipws"<< "noskipws"<< "unitbuf"<< "nounitbuf"<< "uppercase"<< "nouppercase" <<
|
||||||
"fixed", "scientific",
|
"dec"<< "hex"<< "oct" <<
|
||||||
"internal", "left", "right",
|
"fixed"<< "scientific" <<
|
||||||
"fpos", "streamoff", "streampos", "streamsize"
|
"internal"<< "left"<< "right" <<
|
||||||
};
|
"fpos"<< "streamoff"<< "streampos"<< "streamsize";
|
||||||
static const std::set<std::string> stdTypes(stdTypes_, stdTypes_+sizeof(stdTypes_)/sizeof(*stdTypes_));
|
|
||||||
static const char* stdTemplates_[] = {
|
static const std::set<std::string> stdTemplates = make_container<std::set<std::string> >() <<
|
||||||
"array", "basic_string", "bitset", "deque", "list", "map", "multimap",
|
"array"<< "basic_string"<< "bitset"<< "deque"<< "list"<< "map"<< "multimap" <<
|
||||||
"priority_queue", "queue", "set", "multiset", "stack", "vector", "pair",
|
"priority_queue"<< "queue"<< "set"<< "multiset"<< "stack"<< "vector"<< "pair" <<
|
||||||
"iterator", "iterator_traits",
|
"iterator"<< "iterator_traits" <<
|
||||||
"unordered_map", "unordered_multimap", "unordered_set", "unordered_multiset",
|
"unordered_map"<< "unordered_multimap"<< "unordered_set"<< "unordered_multiset" <<
|
||||||
"tuple", "function"
|
"tuple"<< "function";
|
||||||
};
|
static const std::set<std::string> stdFunctions = make_container<std::set<std::string> >() <<
|
||||||
static const std::set<std::string> stdTemplates(stdTemplates_, stdTemplates_+sizeof(stdTemplates_)/sizeof(*stdTemplates_));
|
"getline" <<
|
||||||
static const char* stdFunctions_[] = {
|
"for_each"<< "find"<< "find_if"<< "find_end"<< "find_first_of" <<
|
||||||
"getline",
|
"adjacent_find"<< "count"<< "count_if"<< "mismatch"<< "equal"<< "search"<< "search_n" <<
|
||||||
"for_each", "find", "find_if", "find_end", "find_first_of",
|
"copy"<< "copy_backward"<< "swap"<< "swap_ranges"<< "iter_swap"<< "transform"<< "replace" <<
|
||||||
"adjacent_find", "count", "count_if", "mismatch", "equal", "search", "search_n",
|
"replace_if"<< "replace_copy"<< "replace_copy_if"<< "fill"<< "fill_n"<< "generate"<< "generate_n"<< "remove" <<
|
||||||
"copy", "copy_backward", "swap", "swap_ranges", "iter_swap", "transform", "replace",
|
"remove_if"<< "remove_copy"<< "remove_copy_if" <<
|
||||||
"replace_if", "replace_copy", "replace_copy_if", "fill", "fill_n", "generate", "generate_n", "remove",
|
"unique"<< "unique_copy"<< "reverse"<< "reverse_copy" <<
|
||||||
"remove_if", "remove_copy", "remove_copy_if",
|
"rotate"<< "rotate_copy"<< "random_shuffle"<< "partition"<< "stable_partition" <<
|
||||||
"unique", "unique_copy", "reverse", "reverse_copy",
|
"sort"<< "stable_sort"<< "partial_sort"<< "partial_sort_copy"<< "nth_element" <<
|
||||||
"rotate", "rotate_copy", "random_shuffle", "partition", "stable_partition",
|
"lower_bound"<< "upper_bound"<< "equal_range"<< "binary_search"<< "merge"<< "inplace_merge"<< "includes" <<
|
||||||
"sort", "stable_sort", "partial_sort", "partial_sort_copy", "nth_element",
|
"set_union"<< "set_intersection"<< "set_difference" <<
|
||||||
"lower_bound", "upper_bound", "equal_range", "binary_search", "merge", "inplace_merge", "includes",
|
"set_symmetric_difference"<< "push_heap"<< "pop_heap"<< "make_heap"<< "sort_heap" <<
|
||||||
"set_union", "set_intersection", "set_difference",
|
"min"<< "max"<< "min_element"<< "max_element"<< "lexicographical_compare"<< "next_permutation"<< "prev_permutation" <<
|
||||||
"set_symmetric_difference", "push_heap", "pop_heap", "make_heap", "sort_heap",
|
"advance"<< "back_inserter"<< "distance"<< "front_inserter"<< "inserter" <<
|
||||||
"min", "max", "min_element", "max_element", "lexicographical_compare", "next_permutation", "prev_permutation",
|
"make_pair"<< "make_shared"<< "make_tuple";
|
||||||
"advance", "back_inserter", "distance", "front_inserter", "inserter",
|
|
||||||
"make_pair", "make_shared", "make_tuple"
|
|
||||||
};
|
|
||||||
static const std::set<std::string> stdFunctions(stdFunctions_, stdFunctions_+sizeof(stdFunctions_)/sizeof(*stdFunctions_));
|
|
||||||
const bool isCPP11 = _settings->standards.cpp == Standards::CPP11;
|
const bool isCPP11 = _settings->standards.cpp == Standards::CPP11;
|
||||||
|
|
||||||
for (const Token* tok = Token::findsimplematch(list.front(), "using namespace std ;"); tok; tok = tok->next()) {
|
for (const Token* tok = Token::findsimplematch(list.front(), "using namespace std ;"); tok; tok = tok->next()) {
|
||||||
|
@ -9715,121 +9711,75 @@ void Tokenizer::simplifyMicrosoftMemoryFunctions()
|
||||||
void Tokenizer::simplifyMicrosoftStringFunctions()
|
void Tokenizer::simplifyMicrosoftStringFunctions()
|
||||||
{
|
{
|
||||||
// skip if not Windows
|
// skip if not Windows
|
||||||
if (_settings->platformType == Settings::Win32A ||
|
if (_settings->platformType != Settings::Win32A &&
|
||||||
_settings->platformType == Settings::Win32W ||
|
_settings->platformType != Settings::Win32W &
|
||||||
_settings->platformType == Settings::Win64) {
|
_settings->platformType != Settings::Win64)
|
||||||
|
return;
|
||||||
|
|
||||||
const bool ansi = _settings->platformType == Settings::Win32A;
|
struct triplet {
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
triplet(const char* t, const char* m, const char* u) : tchar(t), mbcs(m), unicode(u) {}
|
||||||
if (Token::simpleMatch(tok, "_topen (")) {
|
triplet(const std::string& t) : tchar(t) {}
|
||||||
tok->str(ansi ? "open" : "_wopen");
|
bool operator <(const triplet& rhs) const {
|
||||||
tok->originalName("_topen");
|
return tchar < rhs.tchar;
|
||||||
} else if (Token::simpleMatch(tok, "_tsopen_s (")) {
|
}
|
||||||
tok->str(ansi ? "_sopen_s" : "_wsopen_s");
|
std::string tchar, mbcs, unicode;
|
||||||
tok->originalName("_tsopen_s");
|
};
|
||||||
} else if (Token::simpleMatch(tok, "_tfopen (")) {
|
const static std::set<triplet> apis = make_container< std::set<triplet> >() <<
|
||||||
tok->str(ansi ? "fopen" : "_wfopen");
|
triplet("_topen", "open", "_wopen") <<
|
||||||
tok->originalName("_tfopen");
|
triplet("_tsopen_s", "_sopen_s", "_wsopen_s") <<
|
||||||
} else if (Token::simpleMatch(tok, "_tfopen_s (")) {
|
triplet("_tfopen", "fopen", "_wfopen") <<
|
||||||
tok->str(ansi ? "fopen_s" : "_wfopen_s");
|
triplet("_tfopen_s", "fopen_s", "_wfopen_s") <<
|
||||||
tok->originalName("_tfopen_s");
|
triplet("_tfreopen", "freopen", "_wfreopen") <<
|
||||||
} else if (Token::simpleMatch(tok, "_tfreopen (")) {
|
triplet("_tfreopen_s", "freopen_s", "_wfreopen_s") <<
|
||||||
tok->str(ansi ? "freopen" : "_wfreopen");
|
triplet("_tcscat", "strcat", "wcscat") <<
|
||||||
tok->originalName("_tfreopen");
|
triplet("_tcschr", "strchr", "wcschr") <<
|
||||||
} else if (Token::simpleMatch(tok, "_tfreopen_s (")) {
|
triplet("_tcscmp", "strcmp", "wcscmp") <<
|
||||||
tok->str(ansi ? "freopen_s" : "_wfreopen_s");
|
triplet("_tcsdup", "strdup", "wcsdup") <<
|
||||||
tok->originalName("_tfreopen_s");
|
triplet("_tcscpy", "strcpy", "wcscpy") <<
|
||||||
} else if (Token::simpleMatch(tok, "_tcscat (")) {
|
triplet("_tcslen", "strlen", "wcslen") <<
|
||||||
tok->str(ansi ? "strcat" : "wcscat");
|
triplet("_tcsncat", "strncat", "wcsncat") <<
|
||||||
tok->originalName("_tcscat");
|
triplet("_tcsncpy", "strncpy", "wcsncpy") <<
|
||||||
} else if (Token::simpleMatch(tok, "_tcschr (")) {
|
triplet("_tcsnlen", "strnlen", "wcsnlen") <<
|
||||||
tok->str(ansi ? "strchr" : "wcschr");
|
triplet("_tcsrchr", "strrchr", "wcsrchr") <<
|
||||||
tok->originalName("_tcschr");
|
triplet("_tcsstr", "strstr", "wcsstr") <<
|
||||||
} else if (Token::simpleMatch(tok, "_tcscmp (")) {
|
triplet("_tcstok", "strtok", "wcstok") <<
|
||||||
tok->str(ansi ? "strcmp" : "wcscmp");
|
triplet("_ftprintf", "fprintf", "fwprintf") <<
|
||||||
tok->originalName("_tcscmp");
|
triplet("_tprintf", "printf", "wprintf") <<
|
||||||
} else if (Token::simpleMatch(tok, "_tcsdup (")) {
|
triplet("_stprintf", "sprintf", "swprintf") <<
|
||||||
tok->str(ansi ? "strdup" : "wcsdup");
|
triplet("_sntprintf", "_snprintf", "_snwprintf") <<
|
||||||
tok->originalName("_tcsdup");
|
triplet("_ftscanf", "fscanf", "fwscanf") <<
|
||||||
} else if (Token::simpleMatch(tok, "_tcscpy (")) {
|
triplet("_tscanf", "scanf", "wscanf") <<
|
||||||
tok->str(ansi ? "strcpy" : "wcscpy");
|
triplet("_stscanf", "sscanf", "swscanf") <<
|
||||||
tok->originalName("_tcscpy");
|
triplet("_ftprintf_s", "fprintf_s", "fwprintf_s") <<
|
||||||
} else if (Token::simpleMatch(tok, "_tcslen (")) {
|
triplet("_tprintf_s", "printf_s", "wprintf_s") <<
|
||||||
tok->str(ansi ? "strlen" : "wcslen");
|
triplet("_stprintf_s", "sprintf_s", "swprintf_s") <<
|
||||||
tok->originalName("_tcslen");
|
triplet("_sntprintf_s", "_snprintf_s", "_snwprintf_s") <<
|
||||||
} else if (Token::simpleMatch(tok, "_tcsncat (")) {
|
triplet("_ftscanf_s", "fscanf_s", "fwscanf_s") <<
|
||||||
tok->str(ansi ? "strncat" : "wcsncat");
|
triplet("_tscanf_s", "scanf_s", "wscanf_s") <<
|
||||||
tok->originalName("_tcsncat");
|
triplet("_stscanf_s", "sscanf_s", "swscanf_s")
|
||||||
} else if (Token::simpleMatch(tok, "_tcsncpy (")) {
|
;
|
||||||
tok->str(ansi ? "strncpy" : "wcsncpy");
|
|
||||||
tok->originalName("_tcsncpy");
|
const bool ansi = _settings->platformType == Settings::Win32A;
|
||||||
} else if (Token::simpleMatch(tok, "_tcsnlen (")) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
tok->str(ansi ? "strnlen" : "wcsnlen");
|
std::set<triplet>::const_iterator match = apis.find(tok->str());
|
||||||
tok->originalName("_tcsnlen");
|
if (match!=apis.end()) {
|
||||||
} else if (Token::simpleMatch(tok, "_tcsrchr (")) {
|
const std::string pattern(match->tchar + " (");
|
||||||
tok->str(ansi ? "strrchr" : "wcsrchr");
|
if (Token::simpleMatch(tok, pattern.c_str())) {
|
||||||
tok->originalName("_tcsrchr");
|
tok->str(ansi ? match->mbcs : match->unicode);
|
||||||
} else if (Token::simpleMatch(tok, "_tcsstr (")) {
|
tok->originalName(match->tchar);
|
||||||
tok->str(ansi ? "strstr" : "wcsstr");
|
}
|
||||||
tok->originalName("_tcsstr");
|
} else if (Token::Match(tok, "_T ( %char%|%str% )")) {
|
||||||
} else if (Token::simpleMatch(tok, "_tcstok (")) {
|
tok->deleteNext();
|
||||||
tok->str(ansi ? "strtok" : "wcstok");
|
tok->deleteThis();
|
||||||
tok->originalName("_tcstok");
|
tok->deleteNext();
|
||||||
} else if (Token::simpleMatch(tok, "_ftprintf (")) {
|
if (!ansi)
|
||||||
tok->str(ansi ? "fprintf" : "fwprintf");
|
tok->isLong(true);
|
||||||
tok->originalName("_ftprintf");
|
while (Token::Match(tok->next(), "_T ( %char%|%str% )")) {
|
||||||
} else if (Token::simpleMatch(tok, "_tprintf (")) {
|
tok->next()->deleteNext();
|
||||||
tok->str(ansi ? "printf" : "wprintf");
|
tok->next()->deleteThis();
|
||||||
tok->originalName("_tprintf");
|
tok->next()->deleteNext();
|
||||||
} else if (Token::simpleMatch(tok, "_stprintf (")) {
|
tok->concatStr(tok->next()->str());
|
||||||
tok->str(ansi ? "sprintf" : "swprintf");
|
|
||||||
tok->originalName("_stprintf");
|
|
||||||
} else if (Token::simpleMatch(tok, "_sntprintf (")) {
|
|
||||||
tok->str(ansi ? "_snprintf" : "_snwprintf");
|
|
||||||
tok->originalName("_sntprintf");
|
|
||||||
} else if (Token::simpleMatch(tok, "_ftscanf (")) {
|
|
||||||
tok->str(ansi ? "fscanf" : "fwscanf");
|
|
||||||
tok->originalName("_ftscanf");
|
|
||||||
} else if (Token::simpleMatch(tok, "_tscanf (")) {
|
|
||||||
tok->str(ansi ? "scanf" : "wscanf");
|
|
||||||
tok->originalName("_tscanf");
|
|
||||||
} else if (Token::simpleMatch(tok, "_stscanf (")) {
|
|
||||||
tok->str(ansi ? "sscanf" : "swscanf");
|
|
||||||
tok->originalName("_stscanf");
|
|
||||||
} else if (Token::simpleMatch(tok, "_ftprintf_s (")) {
|
|
||||||
tok->str(ansi ? "fprintf_s" : "fwprintf_s");
|
|
||||||
tok->originalName("_ftprintf_s");
|
|
||||||
} else if (Token::simpleMatch(tok, "_tprintf_s (")) {
|
|
||||||
tok->str(ansi ? "printf_s" : "wprintf_s");
|
|
||||||
tok->originalName("_tprintf_s");
|
|
||||||
} else if (Token::simpleMatch(tok, "_stprintf_s (")) {
|
|
||||||
tok->str(ansi ? "sprintf_s" : "swprintf_s");
|
|
||||||
tok->originalName("_stprintf_s");
|
|
||||||
} else if (Token::simpleMatch(tok, "_sntprintf_s (")) {
|
|
||||||
tok->str(ansi ? "_snprintf_s" : "_snwprintf_s");
|
|
||||||
tok->originalName("_sntprintf_s");
|
|
||||||
} else if (Token::simpleMatch(tok, "_ftscanf_s (")) {
|
|
||||||
tok->str(ansi ? "fscanf_s" : "fwscanf_s");
|
|
||||||
tok->originalName("_ftscanf_s");
|
|
||||||
} else if (Token::simpleMatch(tok, "_tscanf_s (")) {
|
|
||||||
tok->str(ansi ? "scanf_s" : "wscanf_s");
|
|
||||||
tok->originalName("_tscanf_s");
|
|
||||||
} else if (Token::simpleMatch(tok, "_stscanf_s (")) {
|
|
||||||
tok->str(ansi ? "sscanf_s" : "swscanf_s");
|
|
||||||
tok->originalName("_stscanf_s");
|
|
||||||
} else if (Token::Match(tok, "_T ( %char%|%str% )")) {
|
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
|
||||||
tok->deleteNext();
|
|
||||||
if (!ansi)
|
|
||||||
tok->isLong(true);
|
|
||||||
while (Token::Match(tok->next(), "_T ( %char%|%str% )")) {
|
|
||||||
tok->next()->deleteNext();
|
|
||||||
tok->next()->deleteThis();
|
|
||||||
tok->next()->deleteNext();
|
|
||||||
tok->concatStr(tok->next()->str());
|
|
||||||
tok->deleteNext();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10382,7 +10332,7 @@ void Tokenizer::reportError(const Token* tok, const Severity::SeverityType sever
|
||||||
|
|
||||||
void Tokenizer::reportError(const std::list<const Token*>& callstack, Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive) const
|
void Tokenizer::reportError(const std::list<const Token*>& callstack, Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive) const
|
||||||
{
|
{
|
||||||
ErrorLogger::ErrorMessage errmsg(callstack, &list, severity, id, msg, inconclusive);
|
const ErrorLogger::ErrorMessage errmsg(callstack, &list, severity, id, msg, inconclusive);
|
||||||
if (_errorLogger)
|
if (_errorLogger)
|
||||||
_errorLogger->reportErr(errmsg);
|
_errorLogger->reportErr(errmsg);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue