Support for Sun Studio C++ compiler

This commit is contained in:
acm4me 2012-12-27 11:51:12 +01:00 committed by PKEuS
parent bfb82fe3e1
commit 7da155c8ba
12 changed files with 103 additions and 93 deletions

View File

@ -103,30 +103,30 @@ void CmdLineParser::PrintMessage(const std::string &message)
bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
{ {
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--version") == 0) { if (std::strcmp(argv[i], "--version") == 0) {
_showVersion = true; _showVersion = true;
_exitAfterPrint = true; _exitAfterPrint = true;
return true; return true;
} }
// Flag used for various purposes during debugging // Flag used for various purposes during debugging
else if (strcmp(argv[i], "--debug") == 0) else if (std::strcmp(argv[i], "--debug") == 0)
_settings->debug = _settings->debugwarnings = true; _settings->debug = _settings->debugwarnings = true;
// Show debug warnings // Show debug warnings
else if (strcmp(argv[i], "--debug-warnings") == 0) else if (std::strcmp(argv[i], "--debug-warnings") == 0)
_settings->debugwarnings = true; _settings->debugwarnings = true;
// Print out code that triggers false positive // Print out code that triggers false positive
else if (strcmp(argv[i], "--debug-fp") == 0) else if (std::strcmp(argv[i], "--debug-fp") == 0)
_settings->debugFalsePositive = true; _settings->debugFalsePositive = true;
// Inconclusive checking (still in testing phase) // Inconclusive checking (still in testing phase)
else if (strcmp(argv[i], "--inconclusive") == 0) else if (std::strcmp(argv[i], "--inconclusive") == 0)
_settings->inconclusive = true; _settings->inconclusive = true;
// Enforce language (--language=, -x) // Enforce language (--language=, -x)
else if (strncmp(argv[i], "--language=", 11) == 0 || strcmp(argv[i], "-x") == 0) { else if (std::strncmp(argv[i], "--language=", 11) == 0 || std::strcmp(argv[i], "-x") == 0) {
std::string str; std::string str;
if (argv[i][2]) { if (argv[i][2]) {
str = argv[i]+11; str = argv[i]+11;
@ -150,16 +150,16 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} }
// Filter errors // Filter errors
else if (strncmp(argv[i], "--exitcode-suppressions", 23) == 0) { else if (std::strncmp(argv[i], "--exitcode-suppressions", 23) == 0) {
std::string filename; std::string filename;
// exitcode-suppressions filename.txt // exitcode-suppressions filename.txt
// Deprecated // Deprecated
if (strcmp(argv[i], "--exitcode-suppressions") == 0) { if (std::strcmp(argv[i], "--exitcode-suppressions") == 0) {
++i; ++i;
if (i >= argc || strncmp(argv[i], "-", 1) == 0 || if (i >= argc || std::strncmp(argv[i], "-", 1) == 0 ||
strncmp(argv[i], "--", 2) == 0) { std::strncmp(argv[i], "--", 2) == 0) {
PrintMessage("cppcheck: No filename specified for the '--exitcode-suppressions' option."); PrintMessage("cppcheck: No filename specified for the '--exitcode-suppressions' option.");
return false; return false;
} }
@ -183,15 +183,15 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} }
// Filter errors // Filter errors
else if (strncmp(argv[i], "--suppressions-list=", 20) == 0) { else if (std::strncmp(argv[i], "--suppressions-list=", 20) == 0) {
std::string filename = argv[i]+20; std::string filename = argv[i]+20;
std::ifstream f(filename.c_str()); std::ifstream f(filename.c_str());
if (!f.is_open()) { if (!f.is_open()) {
std::string message("cppcheck: Couldn't open the file: \""); std::string message("cppcheck: Couldn't open the file: \"");
message += filename; message += filename;
message += "\"."; message += "\".";
if (count(filename.begin(), filename.end(), ',') > 0 || if (std::count(filename.begin(), filename.end(), ',') > 0 ||
count(filename.begin(), filename.end(), '.') > 1) { std::count(filename.begin(), filename.end(), '.') > 1) {
// If user tried to pass multiple files (we can only guess that) // If user tried to pass multiple files (we can only guess that)
// e.g. like this: --suppressions-list=a.txt,b.txt // e.g. like this: --suppressions-list=a.txt,b.txt
// print more detailed error message to tell user how he can solve the problem // print more detailed error message to tell user how he can solve the problem
@ -211,7 +211,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
// Filter errors // Filter errors
// This is deprecated, see --supressions-list above // This is deprecated, see --supressions-list above
else if (strcmp(argv[i], "--suppressions") == 0) { else if (std::strcmp(argv[i], "--suppressions") == 0) {
++i; ++i;
if (i >= argc) { if (i >= argc) {
@ -234,7 +234,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} }
} }
else if (strncmp(argv[i], "--suppress=", 11) == 0) { else if (std::strncmp(argv[i], "--suppress=", 11) == 0) {
std::string suppression = argv[i]+11; std::string suppression = argv[i]+11;
const std::string errmsg(_settings->nomsg.addSuppressionLine(suppression)); const std::string errmsg(_settings->nomsg.addSuppressionLine(suppression));
if (!errmsg.empty()) { if (!errmsg.empty()) {
@ -244,21 +244,21 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} }
// Enables inline suppressions. // Enables inline suppressions.
else if (strcmp(argv[i], "--inline-suppr") == 0) else if (std::strcmp(argv[i], "--inline-suppr") == 0)
_settings->_inlineSuppressions = true; _settings->_inlineSuppressions = true;
// Verbose error messages (configuration info) // Verbose error messages (configuration info)
else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) else if (std::strcmp(argv[i], "-v") == 0 || std::strcmp(argv[i], "--verbose") == 0)
_settings->_verbose = true; _settings->_verbose = true;
// Force checking of files that have "too many" configurations // Force checking of files that have "too many" configurations
else if (strcmp(argv[i], "-f") == 0 || strcmp(argv[i], "--force") == 0) else if (std::strcmp(argv[i], "-f") == 0 || std::strcmp(argv[i], "--force") == 0)
_settings->_force = true; _settings->_force = true;
// Output relative paths // Output relative paths
else if (strcmp(argv[i], "-rp") == 0 || strcmp(argv[i], "--relative-paths") == 0) else if (std::strcmp(argv[i], "-rp") == 0 || std::strcmp(argv[i], "--relative-paths") == 0)
_settings->_relativePaths = true; _settings->_relativePaths = true;
else if (strncmp(argv[i], "-rp=", 4) == 0 || strncmp(argv[i], "--relative-paths=", 17) == 0) { else if (std::strncmp(argv[i], "-rp=", 4) == 0 || std::strncmp(argv[i], "--relative-paths=", 17) == 0) {
_settings->_relativePaths = true; _settings->_relativePaths = true;
if (argv[i][argv[i][3]=='='?4:17] != 0) { if (argv[i][argv[i][3]=='='?4:17] != 0) {
std::string paths = argv[i]+(argv[i][3]=='='?4:17); std::string paths = argv[i]+(argv[i][3]=='='?4:17);
@ -275,11 +275,11 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} }
// Write results in results.xml // Write results in results.xml
else if (strcmp(argv[i], "--xml") == 0) else if (std::strcmp(argv[i], "--xml") == 0)
_settings->_xml = true; _settings->_xml = true;
// Define the XML file version (and enable XML output) // Define the XML file version (and enable XML output)
else if (strncmp(argv[i], "--xml-version=", 14) == 0) { else if (std::strncmp(argv[i], "--xml-version=", 14) == 0) {
std::string numberString(argv[i]+14); std::string numberString(argv[i]+14);
std::istringstream iss(numberString); std::istringstream iss(numberString);
@ -299,11 +299,11 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} }
// Only print something when there are errors // Only print something when there are errors
else if (strcmp(argv[i], "-q") == 0 || strcmp(argv[i], "--quiet") == 0) else if (std::strcmp(argv[i], "-q") == 0 || std::strcmp(argv[i], "--quiet") == 0)
_settings->_errorsOnly = true; _settings->_errorsOnly = true;
// Append userdefined code to checked source code // Append userdefined code to checked source code
else if (strncmp(argv[i], "--append=", 9) == 0) { else if (std::strncmp(argv[i], "--append=", 9) == 0) {
const std::string filename = 9 + argv[i]; const std::string filename = 9 + argv[i];
if (!_settings->append(filename)) { if (!_settings->append(filename)) {
PrintMessage("cppcheck: Couldn't open the file: \"" + filename + "\"."); PrintMessage("cppcheck: Couldn't open the file: \"" + filename + "\".");
@ -311,7 +311,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} }
} }
else if (strncmp(argv[i], "--enable=", 9) == 0) { else if (std::strncmp(argv[i], "--enable=", 9) == 0) {
const std::string errmsg = _settings->addEnabled(argv[i] + 9); const std::string errmsg = _settings->addEnabled(argv[i] + 9);
if (!errmsg.empty()) { if (!errmsg.empty()) {
PrintMessage(errmsg); PrintMessage(errmsg);
@ -325,7 +325,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} }
// --error-exitcode=1 // --error-exitcode=1
else if (strncmp(argv[i], "--error-exitcode=", 17) == 0) { else if (std::strncmp(argv[i], "--error-exitcode=", 17) == 0) {
std::string temp = argv[i]+17; std::string temp = argv[i]+17;
std::istringstream iss(temp); std::istringstream iss(temp);
if (!(iss >> _settings->_exitCode)) { if (!(iss >> _settings->_exitCode)) {
@ -336,11 +336,11 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} }
// User define // User define
else if (strncmp(argv[i], "-D", 2) == 0) { else if (std::strncmp(argv[i], "-D", 2) == 0) {
std::string define; std::string define;
// "-D define" // "-D define"
if (strcmp(argv[i], "-D") == 0) { if (std::strcmp(argv[i], "-D") == 0) {
++i; ++i;
if (i >= argc || argv[i][0] == '-') { if (i >= argc || argv[i][0] == '-') {
PrintMessage("cppcheck: argument to '-D' is missing."); PrintMessage("cppcheck: argument to '-D' is missing.");
@ -367,11 +367,11 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
_settings->userDefines += define; _settings->userDefines += define;
} }
// User undef // User undef
else if (strncmp(argv[i], "-U", 2) == 0) { else if (std::strncmp(argv[i], "-U", 2) == 0) {
std::string undef; std::string undef;
// "-U undef" // "-U undef"
if (strcmp(argv[i], "-U") == 0) { if (std::strcmp(argv[i], "-U") == 0) {
++i; ++i;
if (i >= argc || argv[i][0] == '-') { if (i >= argc || argv[i][0] == '-') {
PrintMessage("cppcheck: argument to '-U' is missing."); PrintMessage("cppcheck: argument to '-U' is missing.");
@ -389,11 +389,11 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} }
// Include paths // Include paths
else if (strncmp(argv[i], "-I", 2) == 0) { else if (std::strncmp(argv[i], "-I", 2) == 0) {
std::string path; std::string path;
// "-I path/" // "-I path/"
if (strcmp(argv[i], "-I") == 0) { if (std::strcmp(argv[i], "-I") == 0) {
++i; ++i;
if (i >= argc || argv[i][0] == '-') { if (i >= argc || argv[i][0] == '-') {
PrintMessage("cppcheck: argument to '-I' is missing."); PrintMessage("cppcheck: argument to '-I' is missing.");
@ -414,23 +414,23 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
path += '/'; path += '/';
_settings->_includePaths.push_back(path); _settings->_includePaths.push_back(path);
} else if (strncmp(argv[i], "--includes-file=", 16) == 0) { } else if (std::strncmp(argv[i], "--includes-file=", 16) == 0) {
// open this file and read every input file (1 file name per line) // open this file and read every input file (1 file name per line)
AddInclPathsToList(16 + argv[i], _settings->_includePaths); AddInclPathsToList(16 + argv[i], _settings->_includePaths);
} }
// file list specified // file list specified
else if (strncmp(argv[i], "--file-list=", 12) == 0) { else if (std::strncmp(argv[i], "--file-list=", 12) == 0) {
// open this file and read every input file (1 file name per line) // open this file and read every input file (1 file name per line)
AddFilesToList(12 + argv[i], _pathnames); AddFilesToList(12 + argv[i], _pathnames);
} }
// Ignored paths // Ignored paths
else if (strncmp(argv[i], "-i", 2) == 0) { else if (std::strncmp(argv[i], "-i", 2) == 0) {
std::string path; std::string path;
// "-i path/" // "-i path/"
if (strcmp(argv[i], "-i") == 0) { if (std::strcmp(argv[i], "-i") == 0) {
++i; ++i;
if (i >= argc || argv[i][0] == '-') { if (i >= argc || argv[i][0] == '-') {
PrintMessage("cppcheck: argument to '-i' is missing."); PrintMessage("cppcheck: argument to '-i' is missing.");
@ -459,28 +459,28 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} }
// Report progress // Report progress
else if (strcmp(argv[i], "--report-progress") == 0) { else if (std::strcmp(argv[i], "--report-progress") == 0) {
_settings->reportProgress = true; _settings->reportProgress = true;
} }
// --std // --std
else if (strcmp(argv[i], "--std=posix") == 0) { else if (std::strcmp(argv[i], "--std=posix") == 0) {
_settings->standards.posix = true; _settings->standards.posix = true;
} else if (strcmp(argv[i], "--std=c89") == 0) { } else if (std::strcmp(argv[i], "--std=c89") == 0) {
_settings->standards.c = Standards::C89; _settings->standards.c = Standards::C89;
} else if (strcmp(argv[i], "--std=c99") == 0) { } else if (std::strcmp(argv[i], "--std=c99") == 0) {
_settings->standards.c = Standards::C99; _settings->standards.c = Standards::C99;
} else if (strcmp(argv[i], "--std=c11") == 0) { } else if (std::strcmp(argv[i], "--std=c11") == 0) {
_settings->standards.c = Standards::C11; _settings->standards.c = Standards::C11;
} else if (strcmp(argv[i], "--std=c++03") == 0) { } else if (std::strcmp(argv[i], "--std=c++03") == 0) {
_settings->standards.cpp = Standards::CPP03; _settings->standards.cpp = Standards::CPP03;
} else if (strcmp(argv[i], "--std=c++11") == 0) { } else if (std::strcmp(argv[i], "--std=c++11") == 0) {
_settings->standards.cpp = Standards::CPP11; _settings->standards.cpp = Standards::CPP11;
} }
// Output formatter // Output formatter
else if (strcmp(argv[i], "--template") == 0 || else if (std::strcmp(argv[i], "--template") == 0 ||
strncmp(argv[i], "--template=", 11) == 0) { std::strncmp(argv[i], "--template=", 11) == 0) {
// "--template path/" // "--template path/"
if (argv[i][10] == '=') if (argv[i][10] == '=')
_settings->_outputFormat = argv[i] + 11; _settings->_outputFormat = argv[i] + 11;
@ -501,11 +501,11 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} }
// Checking threads // Checking threads
else if (strncmp(argv[i], "-j", 2) == 0) { else if (std::strncmp(argv[i], "-j", 2) == 0) {
std::string numberString; std::string numberString;
// "-j 3" // "-j 3"
if (strcmp(argv[i], "-j") == 0) { if (std::strcmp(argv[i], "-j") == 0) {
++i; ++i;
if (i >= argc || argv[i][0] == '-') { if (i >= argc || argv[i][0] == '-') {
PrintMessage("cppcheck: argument to '-j' is missing."); PrintMessage("cppcheck: argument to '-j' is missing.");
@ -534,14 +534,14 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} }
// print all possible error messages.. // print all possible error messages..
else if (strcmp(argv[i], "--errorlist") == 0) { else if (std::strcmp(argv[i], "--errorlist") == 0) {
_showErrorMessages = true; _showErrorMessages = true;
_settings->_xml = true; _settings->_xml = true;
_exitAfterPrint = true; _exitAfterPrint = true;
} }
// documentation.. // documentation..
else if (strcmp(argv[i], "--doc") == 0) { else if (std::strcmp(argv[i], "--doc") == 0) {
std::ostringstream doc; std::ostringstream doc;
// Get documentation.. // Get documentation..
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) { for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
@ -558,7 +558,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} }
// show timing information.. // show timing information..
else if (strncmp(argv[i], "--showtime=", 11) == 0) { else if (std::strncmp(argv[i], "--showtime=", 11) == 0) {
const std::string showtimeMode = argv[i] + 11; const std::string showtimeMode = argv[i] + 11;
if (showtimeMode == "file") if (showtimeMode == "file")
_settings->_showtime = SHOWTIME_FILE; _settings->_showtime = SHOWTIME_FILE;
@ -572,14 +572,14 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
#ifdef HAVE_RULES #ifdef HAVE_RULES
// Rule given at command line // Rule given at command line
else if (strncmp(argv[i], "--rule=", 7) == 0) { else if (std::strncmp(argv[i], "--rule=", 7) == 0) {
Settings::Rule rule; Settings::Rule rule;
rule.pattern = 7 + argv[i]; rule.pattern = 7 + argv[i];
_settings->rules.push_back(rule); _settings->rules.push_back(rule);
} }
// Rule file // Rule file
else if (strncmp(argv[i], "--rule-file=", 12) == 0) { else if (std::strncmp(argv[i], "--rule-file=", 12) == 0) {
TiXmlDocument doc; TiXmlDocument doc;
if (doc.LoadFile(12+argv[i])) { if (doc.LoadFile(12+argv[i])) {
TiXmlElement *node = doc.FirstChildElement(); TiXmlElement *node = doc.FirstChildElement();
@ -614,12 +614,12 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
#endif #endif
// Check configuration // Check configuration
else if (strcmp(argv[i], "--check-config") == 0) { else if (std::strcmp(argv[i], "--check-config") == 0) {
_settings->checkConfiguration = true; _settings->checkConfiguration = true;
} }
// Specify platform // Specify platform
else if (strncmp(argv[i], "--platform=", 11) == 0) { else if (std::strncmp(argv[i], "--platform=", 11) == 0) {
std::string platform(11+argv[i]); std::string platform(11+argv[i]);
if (platform == "win32A") if (platform == "win32A")
@ -642,7 +642,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} }
// Set maximum number of #ifdef configurations to check // Set maximum number of #ifdef configurations to check
else if (strncmp(argv[i], "--max-configs=", 14) == 0) { else if (std::strncmp(argv[i], "--max-configs=", 14) == 0) {
_settings->_force = false; _settings->_force = false;
std::istringstream iss(14+argv[i]); std::istringstream iss(14+argv[i]);
@ -658,14 +658,14 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
} }
// Print help // Print help
else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { else if (std::strcmp(argv[i], "-h") == 0 || std::strcmp(argv[i], "--help") == 0) {
_pathnames.clear(); _pathnames.clear();
_showHelp = true; _showHelp = true;
_exitAfterPrint = true; _exitAfterPrint = true;
break; break;
} }
else if (strncmp(argv[i], "-", 1) == 0 || strncmp(argv[i], "--", 2) == 0) { else if (std::strncmp(argv[i], "-", 1) == 0 || std::strncmp(argv[i], "--", 2) == 0) {
std::string message("cppcheck: error: unrecognized command line option: \""); std::string message("cppcheck: error: unrecognized command line option: \"");
message += argv[i]; message += argv[i];
message += "\"."; message += "\".";

View File

@ -40,6 +40,9 @@
#include <errno.h> #include <errno.h>
#endif #endif
// required for FD_ZERO
using std::memset;
ThreadExecutor::ThreadExecutor(const std::map<std::string, std::size_t> &files, Settings &settings, ErrorLogger &errorLogger) ThreadExecutor::ThreadExecutor(const std::map<std::string, std::size_t> &files, Settings &settings, ErrorLogger &errorLogger)
: _files(files), _settings(settings), _errorLogger(errorLogger), _fileCount(0) : _files(files), _settings(settings), _errorLogger(errorLogger), _fileCount(0)
{ {
@ -82,19 +85,19 @@ int ThreadExecutor::handleRead(int rpipe, unsigned int &result)
if (type != REPORT_OUT && type != REPORT_ERROR && type != REPORT_INFO && type != CHILD_END) { if (type != REPORT_OUT && type != REPORT_ERROR && type != REPORT_INFO && type != CHILD_END) {
std::cerr << "#### You found a bug from cppcheck.\nThreadExecutor::handleRead error, type was:" << type << std::endl; std::cerr << "#### You found a bug from cppcheck.\nThreadExecutor::handleRead error, type was:" << type << std::endl;
exit(0); std::exit(0);
} }
unsigned int len = 0; unsigned int len = 0;
if (read(rpipe, &len, sizeof(len)) <= 0) { if (read(rpipe, &len, sizeof(len)) <= 0) {
std::cerr << "#### You found a bug from cppcheck.\nThreadExecutor::handleRead error, type was:" << type << std::endl; std::cerr << "#### You found a bug from cppcheck.\nThreadExecutor::handleRead error, type was:" << type << std::endl;
exit(0); std::exit(0);
} }
char *buf = new char[len]; char *buf = new char[len];
if (read(rpipe, buf, len) <= 0) { if (read(rpipe, buf, len) <= 0) {
std::cerr << "#### You found a bug from cppcheck.\nThreadExecutor::handleRead error, type was:" << type << std::endl; std::cerr << "#### You found a bug from cppcheck.\nThreadExecutor::handleRead error, type was:" << type << std::endl;
exit(0); std::exit(0);
} }
if (type == REPORT_OUT) { if (type == REPORT_OUT) {
@ -154,26 +157,26 @@ unsigned int ThreadExecutor::check()
if (i != _files.end() && rpipes.size() < _settings._jobs) { if (i != _files.end() && rpipes.size() < _settings._jobs) {
int pipes[2]; int pipes[2];
if (pipe(pipes) == -1) { if (pipe(pipes) == -1) {
std::cerr << "pipe() failed: "<< strerror(errno) << std::endl; std::cerr << "pipe() failed: "<< std::strerror(errno) << std::endl;
exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
int flags = 0; int flags = 0;
if ((flags = fcntl(pipes[0], F_GETFL, 0)) < 0) { if ((flags = fcntl(pipes[0], F_GETFL, 0)) < 0) {
std::cerr << "fcntl(F_GETFL) failed: "<< strerror(errno) << std::endl; std::cerr << "fcntl(F_GETFL) failed: "<< std::strerror(errno) << std::endl;
exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
if (fcntl(pipes[0], F_SETFL, flags | O_NONBLOCK) < 0) { if (fcntl(pipes[0], F_SETFL, flags | O_NONBLOCK) < 0) {
std::cerr << "fcntl(F_SETFL) failed: "<< strerror(errno) << std::endl; std::cerr << "fcntl(F_SETFL) failed: "<< std::strerror(errno) << std::endl;
exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
pid_t pid = fork(); pid_t pid = fork();
if (pid < 0) { if (pid < 0) {
// Error // Error
std::cerr << "Failed to create child process: "<< strerror(errno) << std::endl; std::cerr << "Failed to create child process: "<< std::strerror(errno) << std::endl;
exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} else if (pid == 0) { } else if (pid == 0) {
close(pipes[0]); close(pipes[0]);
_wpipe = pipes[1]; _wpipe = pipes[1];
@ -193,7 +196,7 @@ unsigned int ThreadExecutor::check()
std::ostringstream oss; std::ostringstream oss;
oss << resultOfCheck; oss << resultOfCheck;
writeToPipe(CHILD_END, oss.str()); writeToPipe(CHILD_END, oss.str());
exit(0); std::exit(0);
} }
close(pipes[1]); close(pipes[1]);
@ -288,7 +291,7 @@ void ThreadExecutor::writeToPipe(PipeSignal type, const std::string &data)
delete [] out; delete [] out;
out = 0; out = 0;
std::cerr << "#### ThreadExecutor::writeToPipe, Failed to write to pipe" << std::endl; std::cerr << "#### ThreadExecutor::writeToPipe, Failed to write to pipe" << std::endl;
exit(0); std::exit(0);
} }
delete [] out; delete [] out;

View File

@ -94,7 +94,7 @@ static const char * const call_func_white_list[] = {
static int call_func_white_list_compare(const void *a, const void *b) static int call_func_white_list_compare(const void *a, const void *b)
{ {
return strcmp((const char *)a, *(const char * const *)b); return std::strcmp((const char *)a, *(const char * const *)b);
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -1015,7 +1015,7 @@ std::set<std::string> UninitVar::uvarFunctions;
/// @} /// @}
void CheckUninitVar::analyse(const Token * const tokens, std::set<std::string> &func) const void CheckUninitVar::analyse(const Token * tokens, std::set<std::string> &func) const
{ {
UninitVar::analyseFunctions(tokens, func); UninitVar::analyseFunctions(tokens, func);
} }

View File

@ -750,9 +750,9 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
// bailout when for_each is used // bailout when for_each is used
if (Token::Match(tok,"%var% (") && Token::simpleMatch(tok->linkAt(1),") {")) { if (Token::Match(tok,"%var% (") && Token::simpleMatch(tok->linkAt(1),") {")) {
// does the name contain "for_each" or "foreach"? // does the name contain "for_each" or "foreach"?
std::string name(tok->str()); std::string nameTok(tok->str());
std::transform(name.begin(),name.end(),name.begin(),static_cast<int(*)(int)>(std::tolower)); std::transform(nameTok.begin(),nameTok.end(),nameTok.begin(),::tolower);
if (name.find("foreach") != std::string::npos || name.find("for_each") != std::string::npos) { if (nameTok.find("foreach") != std::string::npos || nameTok.find("for_each") != std::string::npos) {
// bailout all variables in the body that are used more than once. // bailout all variables in the body that are used more than once.
// TODO: there is no need to bailout if variable is only read or only written // TODO: there is no need to bailout if variable is only read or only written
std::set<unsigned int> varid; std::set<unsigned int> varid;

View File

@ -304,7 +304,7 @@ std::string MathLib::mod(const std::string &first, const std::string &second)
throw InternalError(0, "Internal Error: Division by zero"); throw InternalError(0, "Internal Error: Division by zero");
return longToString(toLongNumber(first) % b); return longToString(toLongNumber(first) % b);
} }
return doubleToString(fmod(toDoubleNumber(first),toDoubleNumber(second))); return doubleToString(std::fmod(toDoubleNumber(first),toDoubleNumber(second)));
} }
std::string MathLib::calculate(const std::string &first, const std::string &second, char action) std::string MathLib::calculate(const std::string &first, const std::string &second, char action)

View File

@ -58,7 +58,7 @@ std::string Path::fromNativeSeparators(std::string path)
std::string Path::simplifyPath(const char *originalPath) std::string Path::simplifyPath(const char *originalPath)
{ {
// Skip ./ at the beginning // Skip ./ at the beginning
if (strlen(originalPath) > 2 && originalPath[0] == '.' && if (std::strlen(originalPath) > 2 && originalPath[0] == '.' &&
originalPath[1] == '/') { originalPath[1] == '/') {
originalPath += 2; originalPath += 2;
} }

View File

@ -35,6 +35,13 @@
#define LLONG_MAX LONG_MAX #define LLONG_MAX LONG_MAX
#endif #endif
// Define ULLONG_MAX and LLONG_MAX for SunCC on non-Solaris systems
#if (defined(__SUNPRO_C) || defined(__SUNPRO_CC)) && \
!(defined (__sun) || defined (__sun__))
#define ULLONG_MAX ULONG_MAX
#define LLONG_MAX LONG_MAX
#endif
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)

View File

@ -322,7 +322,7 @@ const std::string &Token::strAt(int index) const
static bool strisop(const char str[]) static bool strisop(const char str[])
{ {
if (str[1] == 0) { if (str[1] == 0) {
if (strchr("+-*/%&|^~!<>", *str)) if (std::strchr("+-*/%&|^~!<>", *str))
return true; return true;
} else if (str[2] == 0) { } else if (str[2] == 0) {
if ((str[0] == '&' && str[1] == '&') || if ((str[0] == '&' && str[1] == '&') ||
@ -469,21 +469,21 @@ bool Token::simpleMatch(const Token *tok, const char pattern[])
const char *current, *next; const char *current, *next;
current = pattern; current = pattern;
next = strchr(pattern, ' '); next = std::strchr(pattern, ' ');
if (!next) if (!next)
next = pattern + strlen(pattern); next = pattern + std::strlen(pattern);
while (*current) { while (*current) {
std::size_t length = static_cast<std::size_t>(next - current); std::size_t length = static_cast<std::size_t>(next - current);
if (!tok || length != tok->_str.length() || strncmp(current, tok->_str.c_str(), length)) if (!tok || length != tok->_str.length() || std::strncmp(current, tok->_str.c_str(), length))
return false; return false;
current = next; current = next;
if (*next) { if (*next) {
next = strchr(++current, ' '); next = std::strchr(++current, ' ');
if (!next) if (!next)
next = current + strlen(current); next = current + std::strlen(current);
} }
tok = tok->next(); tok = tok->next();
} }
@ -691,7 +691,7 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
break; break;
default: default:
//unknown %cmd%, abort //unknown %cmd%, abort
abort(); std::abort();
} }
} }

View File

@ -306,7 +306,7 @@ public:
* @param prepend Insert the new token before this token when it's not * @param prepend Insert the new token before this token when it's not
* the first one on the tokens list. * the first one on the tokens list.
*/ */
void insertToken(const std::string &tokenStr, const bool prepend=false); void insertToken(const std::string &tokenStr, bool prepend=false);
Token *previous() const { Token *previous() const {
return _previous; return _previous;

View File

@ -1680,7 +1680,7 @@ bool Tokenizer::tokenize(std::istream &code,
const char c2 = tok->next()->str()[0]; const char c2 = tok->next()->str()[0];
// combine +-*/ and = // combine +-*/ and =
if (c2 == '=' && (strchr("+-*/%&|^=!<>", c1))) { if (c2 == '=' && (std::strchr("+-*/%&|^=!<>", c1))) {
tok->str(tok->str() + c2); tok->str(tok->str() + c2);
tok->deleteNext(); tok->deleteNext();
continue; continue;
@ -5132,7 +5132,7 @@ void Tokenizer::simplifyVarDecl(bool only_k_r_fpar)
else if (tok2->str() == "<" && tok2->previous()->isName() && !tok2->previous()->varId()) else if (tok2->str() == "<" && tok2->previous()->isName() && !tok2->previous()->varId())
tok2->findClosingBracket(tok2); tok2->findClosingBracket(tok2);
else if (strchr(";,", tok2->str()[0])) { else if (std::strchr(";,", tok2->str()[0])) {
// "type var =" => "type var; var =" // "type var =" => "type var; var ="
const Token *VarTok = type0->tokAt((int)typelen); const Token *VarTok = type0->tokAt((int)typelen);
while (Token::Match(VarTok, "*|&|const")) while (Token::Match(VarTok, "*|&|const"))

View File

@ -73,10 +73,10 @@ void TokenList::addtoken(const char str[], const unsigned int lineno, const unsi
return; return;
// If token contains # characters, split it up // If token contains # characters, split it up
if (split && strstr(str, "##")) { if (split && std::strstr(str, "##")) {
std::string temp; std::string temp;
for (unsigned int i = 0; str[i]; ++i) { for (unsigned int i = 0; str[i]; ++i) {
if (strncmp(&str[i], "##", 2) == 0) { if (std::strncmp(&str[i], "##", 2) == 0) {
addtoken(temp.c_str(), lineno, fileno, false); addtoken(temp.c_str(), lineno, fileno, false);
temp.clear(); temp.clear();
addtoken("##", lineno, fileno, false); addtoken("##", lineno, fileno, false);
@ -92,7 +92,7 @@ void TokenList::addtoken(const char str[], const unsigned int lineno, const unsi
std::ostringstream str2; std::ostringstream str2;
if (MathLib::isHex(str) || MathLib::isOct(str) || MathLib::isBin(str)) { if (MathLib::isHex(str) || MathLib::isOct(str) || MathLib::isBin(str)) {
str2 << MathLib::toLongNumber(str); str2 << MathLib::toLongNumber(str);
} else if (strncmp(str, "_Bool", 5) == 0) { } else if (std::strncmp(str, "_Bool", 5) == 0) {
str2 << "bool"; str2 << "bool";
} else { } else {
str2 << str; str2 << str;
@ -273,7 +273,7 @@ bool TokenList::createTokens(std::istream &code, const std::string& file0)
CurrentToken.length() > 0 && CurrentToken.length() > 0 &&
std::isdigit(CurrentToken[0])) { std::isdigit(CurrentToken[0])) {
// Don't separate doubles "5.4" // Don't separate doubles "5.4"
} else if (strchr("+-", ch) && } else if (std::strchr("+-", ch) &&
CurrentToken.length() > 0 && CurrentToken.length() > 0 &&
std::isdigit(CurrentToken[0]) && std::isdigit(CurrentToken[0]) &&
(CurrentToken[CurrentToken.length()-1] == 'e' || (CurrentToken[CurrentToken.length()-1] == 'e' ||
@ -283,7 +283,7 @@ bool TokenList::createTokens(std::istream &code, const std::string& file0)
} else if (CurrentToken.empty() && ch == '.' && std::isdigit(code.peek())) { } else if (CurrentToken.empty() && ch == '.' && std::isdigit(code.peek())) {
// tokenize .125 into 0.125 // tokenize .125 into 0.125
CurrentToken = "0"; CurrentToken = "0";
} else if (strchr("+-*/%&|^?!=<>[](){};:,.~\n ", ch)) { } else if (std::strchr("+-*/%&|^?!=<>[](){};:,.~\n ", ch)) {
if (CurrentToken == "#file") { if (CurrentToken == "#file") {
// Handle this where strings are handled // Handle this where strings are handled
continue; continue;
@ -316,7 +316,7 @@ bool TokenList::createTokens(std::istream &code, const std::string& file0)
CurrentToken += ch; CurrentToken += ch;
// Add "++", "--", ">>" or ... token // Add "++", "--", ">>" or ... token
if (strchr("+-<>=:&|", ch) && (code.peek() == ch)) if (std::strchr("+-<>=:&|", ch) && (code.peek() == ch))
CurrentToken += (char)code.get(); CurrentToken += (char)code.get();
addtoken(CurrentToken.c_str(), lineno, FileIndex); addtoken(CurrentToken.c_str(), lineno, FileIndex);
_back->setExpandedMacro(expandedMacro); _back->setExpandedMacro(expandedMacro);