void TestPatternSearchReplace(const std::string& idPlaceholder, const std::string& id) const { const std::string plainText = "text"; ErrorLogger::ErrorMessage message; message._id = id; std::string serialized = message.toString(true, idPlaceholder + plainText + idPlaceholder); ASSERT_EQUALS(id + plainText + id, serialized); serialized = message.toString(true, idPlaceholder + idPlaceholder); ASSERT_EQUALS(id + id, serialized); serialized = message.toString(true, plainText + idPlaceholder + plainText); ASSERT_EQUALS(plainText + id + plainText, serialized); }
void CppCheck::reportErr(const ErrorLogger::ErrorMessage &msg) { if (!_settings.library.reportErrors(msg.file0)) return; const std::string errmsg = msg.toString(_settings.verbose); if (errmsg.empty()) return; // Alert only about unique errors if (std::find(_errorList.begin(), _errorList.end(), errmsg) != _errorList.end()) return; std::string file; unsigned int line(0); if (!msg._callStack.empty()) { file = msg._callStack.back().getfile(false); line = msg._callStack.back().line; } if (_useGlobalSuppressions) { if (_settings.nomsg.isSuppressed(msg._id, file, line)) return; } else { if (_settings.nomsg.isSuppressedLocal(msg._id, file, line)) return; } if (!_settings.nofail.isSuppressed(msg._id, file, line)) exitcode = 1; _errorList.push_back(errmsg); _errorLogger.reportErr(msg); }
int ThreadExecutor::handleRead(int rpipe, unsigned int &result) { char type = 0; if (read(rpipe, &type, 1) <= 0) { if (errno == EAGAIN) return 0; return -1; } 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; exit(0); } unsigned int 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; exit(0); } char *buf = new char[len]; if (read(rpipe, buf, len) <= 0) { std::cerr << "#### You found a bug from cppcheck.\nThreadExecutor::handleRead error, type was:" << type << std::endl; exit(0); } if (type == REPORT_OUT) { _errorLogger.reportOut(buf); } else if (type == REPORT_ERROR || type == REPORT_INFO) { ErrorLogger::ErrorMessage msg; msg.deserialize(buf); std::string file; unsigned int line(0); if (!msg._callStack.empty()) { file = msg._callStack.back().getfile(false); line = msg._callStack.back().line; } if (!_settings.nomsg.isSuppressed(msg._id, file, line)) { // Alert only about unique errors std::string errmsg = msg.toString(_settings._verbose); if (std::find(_errorList.begin(), _errorList.end(), errmsg) == _errorList.end()) { _errorList.push_back(errmsg); if (type == REPORT_ERROR) _errorLogger.reportErr(msg); else _errorLogger.reportInfo(msg); } } } else if (type == CHILD_END) { std::istringstream iss(buf); unsigned int fileResult = 0; iss >> fileResult; result += fileResult; delete [] buf; return -1; }
void CppCheckExecutor::reportErr(const ErrorLogger::ErrorMessage &msg) { if (errorlist) { reportOut(msg.toXML(false, _settings->_xml_version)); } else if (_settings->_xml) { reportErr(msg.toXML(_settings->_verbose, _settings->_xml_version)); } else { reportErr(msg.toString(_settings->_verbose, _settings->_outputFormat)); } }
void CppCheck::reportErr(const ErrorLogger::ErrorMessage &msg) { const std::string errmsg = msg.toString(_settings._verbose); if (errmsg.empty()) return; if (_settings.debugFalsePositive) { // Don't print out error _errorList.push_back(errmsg); return; } // Alert only about unique errors if (std::find(_errorList.begin(), _errorList.end(), errmsg) != _errorList.end()) return; std::string file; unsigned int line(0); if (!msg._callStack.empty()) { file = msg._callStack.back().getfile(false); line = msg._callStack.back().line; } if (_useGlobalSuppressions) { if (_settings.nomsg.isSuppressed(msg._id, file, line)) return; } else { if (_settings.nomsg.isSuppressedLocal(msg._id, file, line)) return; } if (!_settings.nofail.isSuppressed(msg._id, file, line)) exitcode = 1; _errorList.push_back(errmsg); std::string errmsg2(errmsg); if (_settings._verbose) { errmsg2 += "\n Defines=\'" + cfg + "\'\n"; } _errorLogger.reportErr(msg); _errout << errmsg2 << std::endl; }
void CppCheck::reportErr(const ErrorLogger::ErrorMessage &msg) { mSuppressInternalErrorFound = false; if (!mSettings.library.reportErrors(msg.file0)) return; const std::string errmsg = msg.toString(mSettings.verbose); if (errmsg.empty()) return; // Alert only about unique errors if (std::find(mErrorList.begin(), mErrorList.end(), errmsg) != mErrorList.end()) return; const Suppressions::ErrorMessage errorMessage = msg.toSuppressionsErrorMessage(); if (mUseGlobalSuppressions) { if (mSettings.nomsg.isSuppressed(errorMessage)) { mSuppressInternalErrorFound = true; return; } } else { if (mSettings.nomsg.isSuppressedLocal(errorMessage)) { mSuppressInternalErrorFound = true; return; } } if (!mSettings.nofail.isSuppressed(errorMessage) && (mUseGlobalSuppressions || !mSettings.nomsg.isSuppressed(errorMessage))) mExitCode = 1; mErrorList.push_back(errmsg); mErrorLogger.reportErr(msg); mAnalyzerInformation.reportErr(msg, mSettings.verbose); if (!mSettings.plistOutput.empty() && plistFile.is_open()) { plistFile << ErrorLogger::plistData(msg); } }
void TscThreadExecutor::report(const ErrorLogger::ErrorMessage &msg, MessageType msgType) { std::string file; unsigned int line(0); if (!msg._callStack.empty()) { file = msg._callStack.back().getfile(false); line = msg._callStack.back().line; } if (_settings.nomsg.isSuppressed(msg._id, file, line)) return; // Alert only about unique errors bool reportError = false; std::string errmsg = msg.toString(_settings._verbose); TSC_LOCK_ENTER(&_errorSync); if (std::find(_errorList.begin(), _errorList.end(), errmsg) == _errorList.end()) { _errorList.push_back(errmsg); reportError = true; } TSC_LOCK_LEAVE(&_errorSync); if (reportError) { TSC_LOCK_ENTER(&_reportSync); switch (msgType) { case REPORT_ERROR: _errorLogger.reportErr(msg); break; case REPORT_INFO: _errorLogger.reportInfo(msg); break; } TSC_LOCK_LEAVE(&_reportSync); } }
void TestFixture::reportErr(const ErrorLogger::ErrorMessage &msg) { const std::string errormessage(msg.toString(false)); if (errout.str().find(errormessage) == std::string::npos) errout << errormessage << std::endl; }
void TestFixture::reportErr(const ErrorLogger::ErrorMessage &msg) { errout << msg.toString() << std::endl; }