small utils.h cleanup (#3821)

This commit is contained in:
Oliver Stöneberg 2022-02-11 19:44:08 +01:00 committed by GitHub
parent 5f3ddabd56
commit 6e57cc4323
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 56 additions and 67 deletions

View File

@ -522,7 +522,7 @@ $(libcppdir)/forwardanalyzer.o: lib/forwardanalyzer.cpp lib/analyzer.h lib/astut
$(libcppdir)/importproject.o: lib/importproject.cpp externals/picojson/picojson.h externals/tinyxml2/tinyxml2.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/importproject.o $(libcppdir)/importproject.cpp
$(libcppdir)/infer.o: lib/infer.cpp lib/calculate.h lib/config.h lib/errortypes.h lib/infer.h lib/mathlib.h lib/utils.h lib/valueflow.h lib/valueptr.h
$(libcppdir)/infer.o: lib/infer.cpp lib/calculate.h lib/config.h lib/errortypes.h lib/infer.h lib/mathlib.h lib/valueflow.h lib/valueptr.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/infer.o $(libcppdir)/infer.cpp
$(libcppdir)/library.o: lib/library.cpp externals/tinyxml2/tinyxml2.h lib/astutils.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/valueflow.h
@ -540,7 +540,7 @@ $(libcppdir)/pathanalysis.o: lib/pathanalysis.cpp lib/astutils.h lib/config.h li
$(libcppdir)/pathmatch.o: lib/pathmatch.cpp lib/config.h lib/path.h lib/pathmatch.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/pathmatch.o $(libcppdir)/pathmatch.cpp
$(libcppdir)/platform.o: lib/platform.cpp externals/tinyxml2/tinyxml2.h lib/config.h lib/path.h lib/platform.h lib/utils.h
$(libcppdir)/platform.o: lib/platform.cpp externals/tinyxml2/tinyxml2.h lib/config.h lib/path.h lib/platform.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/platform.o $(libcppdir)/platform.cpp
$(libcppdir)/preprocessor.o: lib/preprocessor.cpp externals/simplecpp/simplecpp.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h
@ -633,7 +633,7 @@ test/testcharvar.o: test/testcharvar.cpp lib/check.h lib/checkother.h lib/color.
test/testclangimport.o: test/testclangimport.cpp lib/clangimport.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h test/testsuite.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testclangimport.o test/testclangimport.cpp
test/testclass.o: test/testclass.cpp externals/tinyxml2/tinyxml2.h lib/check.h lib/checkclass.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h test/testsuite.h
test/testclass.o: test/testclass.cpp externals/tinyxml2/tinyxml2.h lib/check.h lib/checkclass.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h test/testsuite.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testclass.o test/testclass.cpp
test/testcmdlineparser.o: test/testcmdlineparser.cpp cli/cmdlineparser.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h test/redirect.h test/testsuite.h
@ -642,7 +642,7 @@ test/testcmdlineparser.o: test/testcmdlineparser.cpp cli/cmdlineparser.h lib/col
test/testcondition.o: test/testcondition.cpp externals/simplecpp/simplecpp.h externals/tinyxml2/tinyxml2.h lib/check.h lib/checkcondition.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h test/testsuite.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testcondition.o test/testcondition.cpp
test/testconstructors.o: test/testconstructors.cpp lib/check.h lib/checkclass.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h test/testsuite.h
test/testconstructors.o: test/testconstructors.cpp lib/check.h lib/checkclass.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h test/testsuite.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testconstructors.o test/testconstructors.cpp
test/testcppcheck.o: test/testcppcheck.cpp lib/analyzerinfo.h lib/check.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h test/testsuite.h
@ -705,7 +705,7 @@ test/testpath.o: test/testpath.cpp lib/color.h lib/config.h lib/errorlogger.h li
test/testpathmatch.o: test/testpathmatch.cpp lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/pathmatch.h lib/suppressions.h test/testsuite.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testpathmatch.o test/testpathmatch.cpp
test/testplatform.o: test/testplatform.cpp externals/tinyxml2/tinyxml2.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/platform.h lib/suppressions.h lib/utils.h test/testsuite.h
test/testplatform.o: test/testplatform.cpp externals/tinyxml2/tinyxml2.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/platform.h lib/suppressions.h test/testsuite.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testplatform.o test/testplatform.cpp
test/testpostfixoperator.o: test/testpostfixoperator.cpp lib/check.h lib/checkpostfixoperator.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h test/testsuite.h
@ -777,7 +777,7 @@ test/testuninitvar.o: test/testuninitvar.cpp lib/check.h lib/checkuninitvar.h li
test/testunusedfunctions.o: test/testunusedfunctions.cpp lib/check.h lib/checkunusedfunctions.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h test/testsuite.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testunusedfunctions.o test/testunusedfunctions.cpp
test/testunusedprivfunc.o: test/testunusedprivfunc.cpp externals/simplecpp/simplecpp.h lib/check.h lib/checkclass.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h test/testsuite.h
test/testunusedprivfunc.o: test/testunusedprivfunc.cpp externals/simplecpp/simplecpp.h lib/check.h lib/checkclass.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h test/testsuite.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testunusedprivfunc.o test/testunusedprivfunc.cpp
test/testunusedvar.o: test/testunusedvar.cpp externals/simplecpp/simplecpp.h lib/check.h lib/checkunusedvar.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h test/testsuite.h

View File

@ -339,10 +339,10 @@ static void print_stacktrace(FILE* output, bool demangling, int maxdepth, bool l
}
#undef ADDRESSDISPLAYLENGTH
#else
UNUSED(output);
UNUSED(demangling);
UNUSED(maxdepth);
UNUSED(lowMem);
(void)output;
(void)demangling;
(void)maxdepth;
(void)lowMem;
#endif
}
@ -410,7 +410,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
type = (int)uc->uc_mcontext.gregs[REG_ERR] & 2;
}
#else
UNUSED(context);
(void)context;
killid = getpid();
#endif

View File

@ -217,7 +217,8 @@ static std::string addFiles2(std::map<std::string, std::size_t> &files,
dirent entry;
char buf[sizeof(*dir_result) + (sizeof(dir_result->d_name) > 1 ? 0 : NAME_MAX + 1)];
} dir_result_buffer;
UNUSED(dir_result_buffer.buf); // do not trigger cppcheck itself on the "unused buf"
// TODO: suppress instead?
(void)dir_result_buffer.buf; // do not trigger cppcheck itself on the "unused buf"
std::string new_path;
new_path.reserve(path.length() + 100);// prealloc some memory to avoid constant new/deletes in loop

View File

@ -28,6 +28,7 @@
#include "settings.h"
#include "symboldatabase.h"
#include "token.h"
#include "utils.h"
#include "valueflow.h"
#include "valueptr.h"

View File

@ -27,8 +27,8 @@
#include <string>
#include <vector>
#include "config.h"
#include "errortypes.h"
#include "utils.h"
class Function;
class Library;

View File

@ -28,7 +28,6 @@
#include "symboldatabase.h"
#include "token.h"
#include "tokenize.h"
#include "utils.h"
#include "valueflow.h"
#include <algorithm>

View File

@ -28,7 +28,6 @@
#include "errortypes.h"
#include "mathlib.h"
#include "symboldatabase.h"
#include "utils.h"
#include "valueflow.h"
#include <list>

View File

@ -23,9 +23,7 @@
#include "check.h"
#include "config.h"
#include "symboldatabase.h"
#include "tokenize.h"
#include "utils.h"
#include <cstddef>
#include <list>
@ -37,6 +35,11 @@
class ErrorLogger;
class Settings;
class Token;
class Function;
class Scope;
class SymbolDatabase;
class Type;
class Variable;
namespace CTU {
class FileInfo;

View File

@ -26,7 +26,6 @@
#include "config.h"
#include "mathlib.h"
#include "errortypes.h"
#include "utils.h"
#include <set>
#include <string>

View File

@ -27,7 +27,6 @@
#include "errortypes.h"
#include "library.h"
#include "settings.h"
#include "utils.h"
#include <map>
#include <string>

View File

@ -25,7 +25,6 @@
#include "symboldatabase.h"
#include "token.h"
#include "tokenize.h"
#include "utils.h"
#include "valueflow.h"
#include <algorithm>

View File

@ -24,7 +24,6 @@
#include "check.h"
#include "config.h"
#include "errortypes.h"
#include "utils.h"
#include <ostream>
#include <string>

View File

@ -25,7 +25,6 @@
#include "check.h"
#include "config.h"
#include "library.h"
#include "utils.h"
#include <map>
#include <set>

View File

@ -26,7 +26,6 @@
#include "symboldatabase.h"
#include "token.h"
#include "tokenize.h"
#include "utils.h"
#include <algorithm>
#include <unordered_set>

View File

@ -36,7 +36,6 @@
#include "config.h"
#include "errortypes.h"
#include "tokenize.h"
#include "utils.h"
#include <list>
#include <string>

View File

@ -28,7 +28,6 @@
#include "symboldatabase.h"
#include "token.h"
#include "tokenize.h"
#include "utils.h"
#include "valueflow.h"
#include "checkuninitvar.h" // CheckUninitVar::isVariableUsage
@ -41,6 +40,7 @@
#include <memory>
#include <ostream>
#include <set>
#include <type_traits>
#include <utility>
#include <numeric>

View File

@ -25,7 +25,6 @@
#include "check.h"
#include "config.h"
#include "errortypes.h"
#include "utils.h"
#include <string>
#include <vector>

View File

@ -26,7 +26,6 @@
#include "config.h"
#include "errortypes.h"
#include "tokenize.h"
#include "utils.h"
#include "valueflow.h"
#include <string>

View File

@ -27,7 +27,6 @@
#include "ctu.h"
#include "mathlib.h"
#include "errortypes.h"
#include "utils.h"
#include "valueflow.h"
#include <list>

View File

@ -69,4 +69,30 @@
#include <string>
static const std::string emptyString;
// Use the nonneg macro when you want to assert that a variable/argument is not negative
#ifdef __CPPCHECK__
#define nonneg __cppcheck_low__(0)
#elif defined(NONNEG)
// Enable non-negative values checking
// TODO : investigate using annotations/contracts for stronger value checking
#define nonneg unsigned
#else
// Disable non-negative values checking
#define nonneg
#endif
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#define ASAN 1
#endif
#endif
#ifndef ASAN
#ifdef __SANITIZE_ADDRESS__
#define ASAN 1
#else
#define ASAN 0
#endif
#endif
#endif // configH

View File

@ -27,6 +27,7 @@
#include "token.h"
#include "tokenize.h"
#include "tokenlist.h"
#include "utils.h"
#include <cstdint>
#include <cstring>

View File

@ -26,7 +26,6 @@
#include "check.h"
#include "errorlogger.h"
#include "mathlib.h"
#include "utils.h"
#include "valueflow.h"
#include <algorithm>

View File

@ -24,7 +24,6 @@
#include "path.h"
#include "token.h"
#include "tokenlist.h"
#include "utils.h"
#include <algorithm>
#include <array>

View File

@ -142,7 +142,6 @@
#include "token.h"
#include "tokenize.h"
#include "tokenlist.h"
#include "utils.h"
#include <cctype>
#include <climits>

View File

@ -20,7 +20,6 @@
#include "path.h"
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <limits>

View File

@ -22,7 +22,6 @@
//---------------------------------------------------------------------------
#include "config.h"
#include "utils.h"
#include <climits>
#include <string>

View File

@ -26,6 +26,7 @@
#include "settings.h"
#include "symboldatabase.h"
#include "token.h"
#include "utils.h"
#include "valueflow.h"
#include "valueptr.h"
@ -35,6 +36,7 @@
#include <list>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

View File

@ -19,9 +19,12 @@
#ifndef GUARD_PROGRAMMEMORY_H
#define GUARD_PROGRAMMEMORY_H
#include "config.h"
#include "mathlib.h"
#include "utils.h"
#include "valueflow.h" // needed for alias
#include <cstddef>
#include <functional>
#include <map>
#include <unordered_map>

View File

@ -42,6 +42,7 @@
#include <limits>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//---------------------------------------------------------------------------

View File

@ -25,7 +25,6 @@
#include "library.h"
#include "mathlib.h"
#include "token.h"
#include "utils.h"
#include <cctype>
#include <iosfwd>
@ -34,7 +33,6 @@
#include <memory>
#include <set>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

View File

@ -33,6 +33,7 @@
#include <map>
#include <memory>
#include <stack>
#include <type_traits>
#include <utility>
static Token *skipRequires(Token *tok)

View File

@ -24,7 +24,6 @@
#include "config.h"
#include "errortypes.h"
#include "tokenlist.h"
#include "utils.h"
#include <iosfwd>
#include <list>

View File

@ -23,7 +23,6 @@
#include "config.h"
#include "token.h"
#include "utils.h"
#include <iosfwd>
#include <string>

View File

@ -154,32 +154,4 @@ CPPCHECKLIB bool matchglob(const std::string& pattern, const std::string& name);
CPPCHECKLIB bool matchglobs(const std::vector<std::string> &patterns, const std::string &name);
#define UNUSED(x) (void)(x)
// Use the nonneg macro when you want to assert that a variable/argument is not negative
#ifdef __CPPCHECK__
#define nonneg __cppcheck_low__(0)
#elif defined(NONNEG)
// Enable non-negative values checking
// TODO : investigate using annotations/contracts for stronger value checking
#define nonneg unsigned
#else
// Disable non-negative values checking
#define nonneg
#endif
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#define ASAN 1
#endif
#endif
#ifndef ASAN
#ifdef __SANITIZE_ADDRESS__
#define ASAN 1
#else
#define ASAN 0
#endif
#endif
#endif

View File

@ -23,7 +23,6 @@
#include "config.h"
#include "mathlib.h"
#include "utils.h"
#include <algorithm>
#include <cassert>