diff --git a/cli/threadexecutor.cpp b/cli/threadexecutor.cpp index 67c91b947..c0c298f9c 100644 --- a/cli/threadexecutor.cpp +++ b/cli/threadexecutor.cpp @@ -391,10 +391,10 @@ void ThreadExecutor::reportInternalChildErr(const std::string &childname, const #elif defined(THREADING_MODEL_THREAD) -class ThreadExecutor::LogWriter : public ErrorLogger +class ThreadExecutor::SyncLogForwarder : public ErrorLogger { public: - LogWriter(ThreadExecutor &threadExecutor) + SyncLogForwarder(ThreadExecutor &threadExecutor) : mThreadExecutor(threadExecutor), mProcessedFiles(0), mTotalFiles(0), mProcessedSize(0), mTotalFileSize(0) { mItNextFile = threadExecutor.mFiles.begin(); @@ -475,11 +475,11 @@ unsigned int ThreadExecutor::check() std::vector> threadFutures; threadFutures.reserve(mSettings.jobs); - LogWriter logwriter(*this); + SyncLogForwarder logforwarder(*this); for (unsigned int i = 0; i < mSettings.jobs; ++i) { try { - threadFutures.emplace_back(std::async(std::launch::async, threadProc, &logwriter)); + threadFutures.emplace_back(std::async(std::launch::async, threadProc, &logforwarder)); } catch (const std::system_error &e) { std::cerr << "#### ThreadExecutor::check exception :" << e.what() << std::endl; @@ -492,51 +492,51 @@ unsigned int ThreadExecutor::check() }); } -unsigned int STDCALL ThreadExecutor::threadProc(LogWriter* logWriter) +unsigned int STDCALL ThreadExecutor::threadProc(SyncLogForwarder* logForwarder) { unsigned int result = 0; - std::map::const_iterator &itFile = logWriter->mItNextFile; - std::list::const_iterator &itFileSettings = logWriter->mItNextFileSettings; + std::map::const_iterator &itFile = logForwarder->mItNextFile; + std::list::const_iterator &itFileSettings = logForwarder->mItNextFileSettings; // guard static members of CppCheck against concurrent access - logWriter->mFileSync.lock(); + logForwarder->mFileSync.lock(); for (;;) { - if (itFile == logWriter->mThreadExecutor.mFiles.end() && itFileSettings == logWriter->mThreadExecutor.mSettings.project.fileSettings.end()) { - logWriter->mFileSync.unlock(); + if (itFile == logForwarder->mThreadExecutor.mFiles.end() && itFileSettings == logForwarder->mThreadExecutor.mSettings.project.fileSettings.end()) { + logForwarder->mFileSync.unlock(); break; } - CppCheck fileChecker(*logWriter, false, CppCheckExecutor::executeCommand); - fileChecker.settings() = logWriter->mThreadExecutor.mSettings; + CppCheck fileChecker(*logForwarder, false, CppCheckExecutor::executeCommand); + fileChecker.settings() = logForwarder->mThreadExecutor.mSettings; std::size_t fileSize = 0; - if (itFile != logWriter->mThreadExecutor.mFiles.end()) { + if (itFile != logForwarder->mThreadExecutor.mFiles.end()) { const std::string &file = itFile->first; fileSize = itFile->second; ++itFile; - logWriter->mFileSync.unlock(); + logForwarder->mFileSync.unlock(); // Read file from a file result += fileChecker.check(file); } else { // file settings.. const ImportProject::FileSettings &fs = *itFileSettings; ++itFileSettings; - logWriter->mFileSync.unlock(); + logForwarder->mFileSync.unlock(); result += fileChecker.check(fs); - if (logWriter->mThreadExecutor.mSettings.clangTidy) + if (logForwarder->mThreadExecutor.mSettings.clangTidy) fileChecker.analyseClangTidy(fs); } - logWriter->mFileSync.lock(); + logForwarder->mFileSync.lock(); - logWriter->mProcessedSize += fileSize; - logWriter->mProcessedFiles++; - if (!logWriter->mThreadExecutor.mSettings.quiet) { - std::lock_guard lg(logWriter->mReportSync); - CppCheckExecutor::reportStatus(logWriter->mProcessedFiles, logWriter->mTotalFiles, logWriter->mProcessedSize, logWriter->mTotalFileSize); + logForwarder->mProcessedSize += fileSize; + logForwarder->mProcessedFiles++; + if (!logForwarder->mThreadExecutor.mSettings.quiet) { + std::lock_guard lg(logForwarder->mReportSync); + CppCheckExecutor::reportStatus(logForwarder->mProcessedFiles, logForwarder->mTotalFiles, logForwarder->mProcessedSize, logForwarder->mTotalFileSize); } } return result; diff --git a/cli/threadexecutor.h b/cli/threadexecutor.h index 60f09bb05..6bcf248ec 100644 --- a/cli/threadexecutor.h +++ b/cli/threadexecutor.h @@ -75,8 +75,8 @@ private: #elif defined(THREADING_MODEL_THREAD) - class LogWriter; - static unsigned int STDCALL threadProc(LogWriter *threadExecutor); + class SyncLogForwarder; + static unsigned int STDCALL threadProc(SyncLogForwarder *logforwarder); #endif diff --git a/oss-fuzz/main.cpp b/oss-fuzz/main.cpp index ccc5a4ced..8567fb5ca 100644 --- a/oss-fuzz/main.cpp +++ b/oss-fuzz/main.cpp @@ -16,53 +16,30 @@ * along with this program. If not, see . */ -#include "color.h" #include "cppcheck.h" #include "type2.h" +enum class Color; -class CppcheckExecutor : public ErrorLogger { -private: - CppCheck cppcheck; - +class DummyErrorLogger : public ErrorLogger { public: - CppcheckExecutor() - : ErrorLogger() - , cppcheck(*this, false, nullptr) { - cppcheck.settings().addEnabled("all"); - cppcheck.settings().certainty.setEnabled(Certainty::inconclusive, true); - } - - void run(const std::string &code) { - cppcheck.check("test.cpp", code); - } - - void reportOut(const std::string &outmsg, Color) override { - (void)outmsg; - } - void reportErr(const ErrorMessage &msg) override { - (void)msg; - } - void reportProgress(const std::string& filename, - const char stage[], - const std::size_t value) override { - (void)filename; - (void)stage; - (void)value; - } + void reportOut(const std::string&, Color) override {} + void reportErr(const ErrorMessage&) override {} + void reportProgress(const std::string&, + const char[], + const std::size_t) override {} }; - extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataSize) { if (dataSize < 10000) { const std::string code = generateCode2(data, dataSize); - //std::ofstream fout("code.cpp"); - //fout << code; - //fout.close(); - CppcheckExecutor cppcheckExecutor; - cppcheckExecutor.run(code); + DummyErrorLogger errorLogger; + CppCheck cppcheck(errorLogger, false, nullptr); + cppcheck.settings().addEnabled("all"); + cppcheck.settings().certainty.setEnabled(Certainty::inconclusive, true); + cppcheck.check("test.cpp", code); } return 0; } diff --git a/oss-fuzz/translate.cpp b/oss-fuzz/translate.cpp index ef8a7b1b3..5ebddd269 100644 --- a/oss-fuzz/translate.cpp +++ b/oss-fuzz/translate.cpp @@ -1,3 +1,20 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2022 Cppcheck team. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include #include diff --git a/oss-fuzz/type2.cpp b/oss-fuzz/type2.cpp index 61fbe8ded..f88f4943f 100644 --- a/oss-fuzz/type2.cpp +++ b/oss-fuzz/type2.cpp @@ -1,9 +1,24 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2022 Cppcheck team. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include #include "type2.h" - - static int getValue(const uint8_t *data, size_t dataSize, uint8_t maxValue, bool *done = nullptr) { static size_t pos; // current "data" position diff --git a/oss-fuzz/type2.h b/oss-fuzz/type2.h index 36bd9a682..8a7997b19 100644 --- a/oss-fuzz/type2.h +++ b/oss-fuzz/type2.h @@ -1,3 +1,20 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2022 Cppcheck team. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #pragma once