Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/selfcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ jobs:

- name: Self check (unusedFunction / no test / no gui)
run: |
supprs="--suppress=unusedFunction:lib/errorlogger.h:193 --suppress=unusedFunction:lib/importproject.cpp:1516 --suppress=unusedFunction:lib/importproject.cpp:1540"
supprs="--suppress=unusedFunction:lib/errorlogger.h:196 --suppress=unusedFunction:lib/importproject.cpp:1516 --suppress=unusedFunction:lib/importproject.cpp:1540"
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib -D__CPPCHECK__ -D__GNUC__ --enable=unusedFunction,information --exception-handling -rp=. --project=cmake.output.notest_nogui/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr $supprs
env:
DISABLE_VALUEFLOW: 1
Expand Down
3 changes: 3 additions & 0 deletions lib/calculate.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ bool isZero(T x)
return isEqual(x, T(0));
}

/**
* @throws InternalError thrown in case of unknown operator
*/
template<class R, class T>
R calculate(const std::string& s, const T& x, const T& y, bool* error = nullptr)
{
Expand Down
4 changes: 3 additions & 1 deletion lib/checkleakautovar.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ class CPPCHECKLIB CheckLeakAutoVar : public Check {
/** check for leaks in all scopes */
void check();

/** check for leaks in a function scope */
/** check for leaks in a function scope
* @throws InternalError thrown if recursion count is exceeded
*/
bool checkScope(const Token * startToken,
VarInfo &varInfo,
std::set<int> notzero,
Expand Down
3 changes: 3 additions & 0 deletions lib/checkother.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ class CPPCHECKLIB CheckOther : public Check {

void checkModuloOfOne();

/**
* @throws InternalError thrown if largest union member could not be found
*/
void checkUnionZeroInit();

void checkOverlappingWrite();
Expand Down
9 changes: 9 additions & 0 deletions lib/clangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ namespace clangimport {
std::vector<AstNodePtr> children;

bool isPrologueTypedefDecl() const;
/**
* @throws InternalError thrown if AST location is invalid
*/
void setLocations(TokenList &tokenList, int file, int line, int col);

void dumpAst(int num = 0, int indent = 0) const;
Expand All @@ -350,6 +353,9 @@ namespace clangimport {
mData->mNotScope.clear();
}

/**
* @throws InternalError thrown if index is out of bounds
*/
AstNodePtr getChild(int c) {
if (c >= children.size()) {
std::ostringstream err;
Expand All @@ -361,6 +367,9 @@ namespace clangimport {
return children[c];
}
private:
/**
* @throws InternalError thrown if CXXForRangeStmt cannot be imported
*/
Token *createTokens(TokenList &tokenList);
Token *addtoken(TokenList &tokenList, const std::string &str, bool valueType=true);
const ::Type *addTypeTokens(TokenList &tokenList, const std::string &str, const Scope *scope = nullptr);
Expand Down
3 changes: 3 additions & 0 deletions lib/clangimport.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
class Tokenizer;

namespace clangimport {
/**
* @throws InternalError thrown on incorrectly linked tokens
*/
void CPPCHECKLIB parseClangAstDump(Tokenizer &tokenizer, std::istream &f);
}

Expand Down
3 changes: 3 additions & 0 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@ static std::string detectPython(const CppCheck::ExecuteCmdFn &executeCommand)
return "";
}

/**
* @throws InternalError thrown when execution fails
*/
static std::vector<picojson::value> executeAddon(const AddonInfo &addonInfo,
const std::string &defaultPythonExe,
const std::string &file,
Expand Down
3 changes: 3 additions & 0 deletions lib/errorlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ class CPPCHECKLIB ErrorMessage {
const std::string &templateLocation) const;

std::string serialize() const;
/**
* @throws InternalError thrown if deserialization failed
*/
void deserialize(const std::string &data);

std::list<FileLocation> callStack;
Expand Down
2 changes: 1 addition & 1 deletion lib/errortypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ std::string severityToString(Severity severity)
case Severity::internal:
return "internal";
}
throw InternalError(nullptr, "Unknown severity");
cppcheck::unreachable();
}

// TODO: bail out on invalid severity
Expand Down
3 changes: 3 additions & 0 deletions lib/forwardanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,9 @@ namespace {
return updateRange(endBlock->link(), endBlock, depth);
}

/**
* @throws InternalError thrown on cyclic analysis
*/
Progress updateRange(Token* start, const Token* end, int depth = 20) {
if (depth < 0)
return Break(Analyzer::Terminate::Bail);
Expand Down
33 changes: 30 additions & 3 deletions lib/mathlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class CPPCHECKLIB MathLib {
void promote(const value &v);

public:
/**
* @throws InternalError thrown on invalid value
*/
explicit value(const std::string &s);
std::string str() const;
bool isInt() const {
Expand All @@ -71,28 +74,43 @@ class CPPCHECKLIB MathLib {
return isFloat() ? mDoubleValue : static_cast<double>(mIntValue);
}

/**
* @throws InternalError thrown on invalid/unhandled calculation or divison by zero
*/
static value calc(char op, const value &v1, const value &v2);
int compare(const value &v) const;
value add(int v) const;
/**
* @throws InternalError thrown if operand is not an integer
*/
value shiftLeft(const value &v) const;
/**
* @throws InternalError thrown if operand is not an integer
*/
value shiftRight(const value &v) const;
};

static const int bigint_bits;

/** @brief for conversion of numeric literals - for atoi-like conversions please use strToInt() */
static bigint toBigNumber(const Token * tok);
/** @brief for conversion of numeric literals - for atoi-like conversions please use strToInt() */
/** @brief for conversion of numeric literals - for atoi-like conversions please use strToInt()
* @throws InternalError thrown if conversion failed
*/
static bigint toBigNumber(const std::string & str, const Token *tok = nullptr);
/** @brief for conversion of numeric literals - for atoi-like conversions please use strToInt() */
static biguint toBigUNumber(const Token * tok);
/** @brief for conversion of numeric literals - for atoi-like conversions please use strToInt() */
/** @brief for conversion of numeric literals - for atoi-like conversions please use strToInt()
* @throws InternalError thrown if conversion failed
*/
static biguint toBigUNumber(const std::string & str, const Token *tok = nullptr);

template<class T> static std::string toString(T value) = delete;
/** @brief for conversion of numeric literals */
static double toDoubleNumber(const Token * tok);
/** @brief for conversion of numeric literals */
/** @brief for conversion of numeric literals
* @throws InternalError thrown if conversion failed
*/
static double toDoubleNumber(const std::string & str, const Token * tok = nullptr);

static bool isInt(const std::string & str);
Expand All @@ -119,8 +137,17 @@ class CPPCHECKLIB MathLib {
static std::string add(const std::string & first, const std::string & second);
static std::string subtract(const std::string & first, const std::string & second);
static std::string multiply(const std::string & first, const std::string & second);
/**
* @throws InternalError thrown on overflow or divison by zero
*/
static std::string divide(const std::string & first, const std::string & second);
/**
* @throws InternalError thrown on division by zero
*/
static std::string mod(const std::string & first, const std::string & second);
/**
* @throws InternalError thrown on unexpected action
*/
static std::string calculate(const std::string & first, const std::string & second, char action);

static std::string sin(const std::string & tok);
Expand Down
3 changes: 3 additions & 0 deletions lib/reverseanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ namespace {
return nullptr;
}

/**
* @throws InternalError thrown on cyclic analysis
*/
void traverse(Token* start, const Token* end = nullptr) {
if (start == end)
return;
Expand Down
10 changes: 10 additions & 0 deletions lib/symboldatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,9 @@ class CPPCHECKLIB Function {
nonneg int initializedArgCount() const {
return initArgCount;
}
/**
* @throws InternalError thrown on unrecognized lambda
*/
void addArguments(const Scope *scope);

/** @brief check if this function is virtual in the base classes */
Expand Down Expand Up @@ -1438,6 +1441,9 @@ class CPPCHECKLIB SymbolDatabase {
friend class Function;

// Create symboldatabase...
/**
* @throws InternalError thrown on unhandled code
*/
void createSymbolDatabaseFindAllScopes();
void createSymbolDatabaseClassInfo();
void createSymbolDatabaseVariableInfo();
Expand All @@ -1461,6 +1467,9 @@ class CPPCHECKLIB SymbolDatabase {
void addClassFunction(Scope *&scope, const Token *&tok, const Token *argStart);
RET_NONNULL static Function *addGlobalFunctionDecl(Scope*& scope, const Token* tok, const Token *argStart, const Token* funcStart);
Function *addGlobalFunction(Scope*& scope, const Token*& tok, const Token *argStart, const Token* funcStart);
/**
* @throws InternalError thrown on unrecognized function
*/
void addNewFunction(Scope *&scope, const Token *&tok);
bool isFunction(const Token *tok, const Scope* outerScope, const Token *&funcStart, const Token *&argStart, const Token*& declEnd) const;
const Type *findTypeInNested(const Token *startTok, const Scope *startScope) const;
Expand All @@ -1485,6 +1494,7 @@ class CPPCHECKLIB SymbolDatabase {
void validateExecutableScopes() const;
/**
* @brief Check variable list, e.g. variables w/o scope
* @throws InternalError thrown on variable without scope
*/
void validateVariables() const;

Expand Down
14 changes: 9 additions & 5 deletions lib/templatesimplifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@ class CPPCHECKLIB TemplateSimplifier {
TokenAndName(Token *token, std::string scope);
/**
* Constructor used for declarations.
* \param token template declaration token "template < ... >"
* \param scope full qualification of template(scope)
* \param nameToken template name token "template < ... > class name"
* \param paramEnd template parameter end token ">"
* @param token template declaration token "template < ... >"
* @param scope full qualification of template(scope)
* @param nameToken template name token "template < ... > class name"
* @param paramEnd template parameter end token ">"
* @throws InternalError thrown on template issues
*/
TokenAndName(Token *token, std::string scope, const Token *nameToken, const Token *paramEnd);
TokenAndName(const TokenAndName& other);
Expand Down Expand Up @@ -319,6 +320,7 @@ class CPPCHECKLIB TemplateSimplifier {
* @param tok start token
* @return true if modifications to token-list are done.
* false if no modifications are done.
* @throws InternalError thrown on division by zero in template instantiation
*/
static bool simplifyNumericCalculations(Token *tok, bool isTemplate = true);

Expand Down Expand Up @@ -459,7 +461,9 @@ class CPPCHECKLIB TemplateSimplifier {
*/
static bool removeTemplate(Token *tok, std::map<Token*, Token*>* forwardDecls = nullptr);

/** Syntax error */
/** Syntax error
* @throws InternalError thrown unconditionally
*/
NORETURN static void syntaxError(const Token *tok);

static bool matchSpecialization(
Expand Down
3 changes: 3 additions & 0 deletions lib/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ void Token::replace(Token *replaceThis, Token *start, Token *end)
delete replaceThis;
}

/**
* @throws InternalError thrown on unexpected command or missing varid with %varid%
*/
static
#if defined(__GNUC__)
// GCC does not inline this by itself
Expand Down
13 changes: 12 additions & 1 deletion lib/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,9 @@ class CPPCHECKLIB Token {
return tok;
}

/**
* @throws InternalError thrown if index is out of range
*/
template<class T, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*> )>
static T *linkAtImpl(T *thisTok, int index)
{
Expand Down Expand Up @@ -1532,7 +1535,9 @@ class CPPCHECKLIB Token {
}

/** Updates internal property cache like _isName or _isBoolean.
Called after any mStr() modification. */
Called after any mStr() modification.
@throws InternalError thrown if a bool literal has a varid
*/
void update_property_info();

/** Update internal property cache about isStandardType() */
Expand All @@ -1548,6 +1553,9 @@ class CPPCHECKLIB Token {
public:
void astOperand1(Token *tok);
void astOperand2(Token *tok);
/**
* @throws InternalError thrown on cyclic dependency
*/
void astParent(Token* tok);

Token * astOperand1() {
Expand Down Expand Up @@ -1602,6 +1610,9 @@ class CPPCHECKLIB Token {
return ret;
}

/**
* @throws InternalError thrown if start or end cannot be found
*/
std::pair<const Token *, const Token *> findExpressionStartEndTokens() const;

/**
Expand Down
6 changes: 6 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,9 @@ namespace {
return mNameToken ? mNameToken->str() : "";
}

/**
* @throws InternalError thrown if simplification failed
*/
void replace(Token* tok, const std::string &originalname) {
if (tok == mNameToken)
return;
Expand Down Expand Up @@ -4242,6 +4245,9 @@ void VariableMap::addVariable(const std::string& varname, bool globalNamespace)
it->second = ++mVarId;
}

/**
* @throws Token* thrown when closing brackets are missing
*/
static bool setVarIdParseDeclaration(Token*& tok, const VariableMap& variableMap, bool executableScope, Standards::cstd_t cStandard)
{
const Token* const tok1 = tok;
Expand Down
16 changes: 12 additions & 4 deletions lib/tokenize.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,17 +376,25 @@ class CPPCHECKLIB Tokenizer {

public:

/** Syntax error */
/** Syntax error
* @throws InternalError thrown unconditionally
*/
NORETURN void syntaxError(const Token *tok, const std::string &code = "") const;

/** Syntax error. Unmatched character. */
/** Syntax error. Unmatched character.
* @throws InternalError thrown unconditionally
*/
NORETURN void unmatchedToken(const Token *tok) const;

private:
/** Syntax error. C++ code in C file. */
/** Syntax error. C++ code in C file.
* @throws InternalError thrown unconditionally
*/
NORETURN void syntaxErrorC(const Token *tok, const std::string &what) const;

/** Warn about unknown macro(s), configuration is recommended */
/** Warn about unknown macro(s), configuration is recommended
* @throws InternalError thrown unconditionally
*/
NORETURN void unknownMacroError(const Token *tok1) const;

void unhandledCharLiteral(const Token *tok, const std::string& msg) const;
Expand Down
Loading
Loading