Fixed #4520 (segmentation fault of cppcheck (preprocessing))
This commit is contained in:
parent
fb480ebb0a
commit
b6bcdf2936
|
@ -210,9 +210,9 @@ unsigned int CppCheck::processFile(const std::string& filename)
|
|||
}
|
||||
}
|
||||
} catch (const std::runtime_error &e) {
|
||||
// Exception was thrown when checking this file..
|
||||
const std::string fixedpath = Path::toNativeSeparators(filename);
|
||||
_errorLogger.reportOut("Bailing out from checking " + fixedpath + ": " + e.what());
|
||||
internalError(filename, e.what());
|
||||
} catch (const InternalError &e) {
|
||||
internalError(filename, e.errorMessage);
|
||||
}
|
||||
|
||||
if (!_settings._errorsOnly)
|
||||
|
@ -222,6 +222,29 @@ unsigned int CppCheck::processFile(const std::string& filename)
|
|||
return exitcode;
|
||||
}
|
||||
|
||||
void CppCheck::internalError(const std::string &filename, const std::string &msg)
|
||||
{
|
||||
const std::string fixedpath = Path::toNativeSeparators(filename);
|
||||
const std::string fullmsg("Bailing out from checking " + fixedpath + " since there was a internal error: " + msg);
|
||||
|
||||
if (_settings.isEnabled("information")) {
|
||||
const ErrorLogger::ErrorMessage::FileLocation loc1(filename, 0);
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> callstack;
|
||||
callstack.push_back(loc1);
|
||||
|
||||
ErrorLogger::ErrorMessage errmsg(callstack,
|
||||
Severity::information,
|
||||
fullmsg,
|
||||
"internalError",
|
||||
false);
|
||||
|
||||
_errorLogger.reportErr(errmsg);
|
||||
|
||||
} else {
|
||||
// Report on stdout
|
||||
_errorLogger.reportOut(fullmsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CppCheck::checkFunctionUsage()
|
||||
|
|
|
@ -135,6 +135,9 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
/** @brief There has been a internal error => Report information message */
|
||||
void internalError(const std::string &filename, const std::string &msg);
|
||||
|
||||
/** @brief Process one file. */
|
||||
unsigned int processFile(const std::string& filename);
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
#include <cctype>
|
||||
#include <limits>
|
||||
|
||||
MathLib::bigint MathLib::toLongNumber(const std::string &str)
|
||||
{
|
||||
|
@ -280,7 +281,10 @@ std::string MathLib::subtract(const std::string &first, const std::string &secon
|
|||
std::string MathLib::divide(const std::string &first, const std::string &second)
|
||||
{
|
||||
if (MathLib::isInt(first) && MathLib::isInt(second)) {
|
||||
bigint a = toLongNumber(first);
|
||||
bigint b = toLongNumber(second);
|
||||
if (a == std::numeric_limits<bigint>::min())
|
||||
throw InternalError(0, "Internal Error: Division overflow");
|
||||
if (b == 0)
|
||||
throw InternalError(0, "Internal Error: Division by zero");
|
||||
return longToString(toLongNumber(first) / b);
|
||||
|
|
|
@ -124,6 +124,7 @@ private:
|
|||
ASSERT_EQUALS("7.0" , MathLib::divide("21.", "3"));
|
||||
ASSERT_EQUALS("1" , MathLib::divide("3", "2"));
|
||||
ASSERT_THROW(MathLib::divide("123", "0"), InternalError); // throw
|
||||
ASSERT_THROW(MathLib::divide("-9223372036854775808", "-1"), InternalError); // #4520 - out of range => throw
|
||||
MathLib::divide("123", "0.0"); // don't throw
|
||||
|
||||
// Unknown action should throw exception
|
||||
|
|
Loading…
Reference in New Issue