made `Platform` a member of `Settings` instead of inheriting from it / cleanups (#4791)
This commit is contained in:
parent
8023eff7c0
commit
5af6ca6637
|
@ -608,7 +608,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
|||
|
||||
std::string errstr;
|
||||
const std::vector<std::string> paths = {argv[0]};
|
||||
if (!mSettings->platform(platform, errstr, paths)) {
|
||||
if (!mSettings->platform.set(platform, errstr, paths)) {
|
||||
printError(errstr);
|
||||
return false;
|
||||
}
|
||||
|
@ -621,9 +621,9 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
|||
// these are loaded via external files and thus have Settings::PlatformFile set instead.
|
||||
// override the type so they behave like the regular platforms.
|
||||
if (platform == "unix32-unsigned")
|
||||
mSettings->platformType = Settings::Unix32;
|
||||
mSettings->platform.type = cppcheck::Platform::Type::Unix32;
|
||||
else if (platform == "unix64-unsigned")
|
||||
mSettings->platformType = Settings::Unix64;
|
||||
mSettings->platform.type = cppcheck::Platform::Type::Unix64;
|
||||
}
|
||||
|
||||
// Write results in results.plist
|
||||
|
@ -679,7 +679,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
|||
|
||||
std::string errstr;
|
||||
const std::vector<std::string> paths = {projectFile, argv[0]};
|
||||
if (!mSettings->platform(platform, errstr, paths)) {
|
||||
if (!mSettings->platform.set(platform, errstr, paths)) {
|
||||
printError(errstr);
|
||||
return false;
|
||||
}
|
||||
|
@ -692,7 +692,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
|||
}
|
||||
if (projType == ImportProject::Type::VS_SLN || projType == ImportProject::Type::VS_VCXPROJ) {
|
||||
if (mSettings->project.guiProject.analyzeAllVsConfigs == "false")
|
||||
mSettings->project.selectOneVsConfig(mSettings->platformType);
|
||||
mSettings->project.selectOneVsConfig(mSettings->platform.type);
|
||||
if (!CppCheckExecutor::tryLoadLibrary(mSettings->library, argv[0], "windows.cfg")) {
|
||||
// This shouldn't happen normally.
|
||||
printError("failed to load 'windows.cfg'. Your Cppcheck installation is broken. Please re-install.");
|
||||
|
|
|
@ -257,11 +257,11 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
|
|||
// For other platforms default to unspecified/default which means the
|
||||
// platform Cppcheck GUI was compiled on.
|
||||
#if defined(_WIN32)
|
||||
const cppcheck::Platform::PlatformType defaultPlatform = cppcheck::Platform::Win32W;
|
||||
const cppcheck::Platform::Type defaultPlatform = cppcheck::Platform::Type::Win32W;
|
||||
#else
|
||||
const cppcheck::Platform::PlatformType defaultPlatform = cppcheck::Platform::Unspecified;
|
||||
const cppcheck::Platform::Type defaultPlatform = cppcheck::Platform::Type::Unspecified;
|
||||
#endif
|
||||
Platform &platform = mPlatforms.get((cppcheck::Platform::PlatformType)mSettings->value(SETTINGS_CHECKED_PLATFORM, defaultPlatform).toInt());
|
||||
Platform &platform = mPlatforms.get((cppcheck::Platform::Type)mSettings->value(SETTINGS_CHECKED_PLATFORM, defaultPlatform).toInt());
|
||||
platform.mActMainWindow->setChecked(true);
|
||||
|
||||
mNetworkAccessManager = new QNetworkAccessManager(this);
|
||||
|
@ -477,7 +477,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, cons
|
|||
p.ignorePaths(v);
|
||||
|
||||
if (!mProjectFile->getAnalyzeAllVsConfigs()) {
|
||||
const cppcheck::Platform::PlatformType platform = (cppcheck::Platform::PlatformType) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt();
|
||||
const cppcheck::Platform::Type platform = (cppcheck::Platform::Type) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt();
|
||||
p.selectOneVsConfig(platform);
|
||||
}
|
||||
} else {
|
||||
|
@ -941,12 +941,12 @@ Settings MainWindow::getCppcheckSettings()
|
|||
const QString platform = mProjectFile->getPlatform();
|
||||
if (platform.endsWith(".xml")) {
|
||||
const QString applicationFilePath = QCoreApplication::applicationFilePath();
|
||||
result.loadPlatformFile(applicationFilePath.toStdString().c_str(), platform.toStdString());
|
||||
result.platform.loadFromFile(applicationFilePath.toStdString().c_str(), platform.toStdString());
|
||||
} else {
|
||||
for (int i = cppcheck::Platform::Native; i <= cppcheck::Platform::Unix64; i++) {
|
||||
const cppcheck::Platform::PlatformType p = (cppcheck::Platform::PlatformType)i;
|
||||
if (platform == cppcheck::Platform::platformString(p)) {
|
||||
result.platform(p);
|
||||
for (int i = cppcheck::Platform::Type::Native; i <= cppcheck::Platform::Type::Unix64; i++) {
|
||||
const cppcheck::Platform::Type p = (cppcheck::Platform::Type)i;
|
||||
if (platform == cppcheck::Platform::toString(p)) {
|
||||
result.platform.set(p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1029,8 +1029,8 @@ Settings MainWindow::getCppcheckSettings()
|
|||
result.jobs = mSettings->value(SETTINGS_CHECK_THREADS, 1).toInt();
|
||||
result.inlineSuppressions = mSettings->value(SETTINGS_INLINE_SUPPRESSIONS, false).toBool();
|
||||
result.certainty.setEnabled(Certainty::inconclusive, mSettings->value(SETTINGS_INCONCLUSIVE_ERRORS, false).toBool());
|
||||
if (!mProjectFile || result.platformType == cppcheck::Platform::Unspecified)
|
||||
result.platform((cppcheck::Platform::PlatformType) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt());
|
||||
if (!mProjectFile || result.platform.type == cppcheck::Platform::Type::Unspecified)
|
||||
result.platform.set((cppcheck::Platform::Type) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt());
|
||||
result.standards.setCPP(mSettings->value(SETTINGS_STD_CPP, QString()).toString().toStdString());
|
||||
result.standards.setC(mSettings->value(SETTINGS_STD_C, QString()).toString().toStdString());
|
||||
result.enforcedLang = (Settings::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt();
|
||||
|
@ -1908,7 +1908,7 @@ void MainWindow::selectPlatform()
|
|||
{
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
if (action) {
|
||||
const cppcheck::Platform::PlatformType platform = (cppcheck::Platform::PlatformType) action->data().toInt();
|
||||
const cppcheck::Platform::Type platform = (cppcheck::Platform::Type) action->data().toInt();
|
||||
mSettings->setValue(SETTINGS_CHECKED_PLATFORM, platform);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ Platforms::Platforms(QObject *parent)
|
|||
init();
|
||||
}
|
||||
|
||||
void Platforms::add(const QString &title, cppcheck::Platform::PlatformType platform)
|
||||
void Platforms::add(const QString &title, cppcheck::Platform::Type platform)
|
||||
{
|
||||
Platform plat;
|
||||
plat.mTitle = title;
|
||||
|
@ -35,12 +35,12 @@ void Platforms::add(const QString &title, cppcheck::Platform::PlatformType platf
|
|||
|
||||
void Platforms::init()
|
||||
{
|
||||
add(tr("Native"), cppcheck::Platform::Native);
|
||||
add(tr("Unix 32-bit"), cppcheck::Platform::Unix32);
|
||||
add(tr("Unix 64-bit"), cppcheck::Platform::Unix64);
|
||||
add(tr("Windows 32-bit ANSI"), cppcheck::Platform::Win32A);
|
||||
add(tr("Windows 32-bit Unicode"), cppcheck::Platform::Win32W);
|
||||
add(tr("Windows 64-bit"), cppcheck::Platform::Win64);
|
||||
add(tr("Native"), cppcheck::Platform::Type::Native);
|
||||
add(tr("Unix 32-bit"), cppcheck::Platform::Type::Unix32);
|
||||
add(tr("Unix 64-bit"), cppcheck::Platform::Type::Unix64);
|
||||
add(tr("Windows 32-bit ANSI"), cppcheck::Platform::Type::Win32A);
|
||||
add(tr("Windows 32-bit Unicode"), cppcheck::Platform::Type::Win32W);
|
||||
add(tr("Windows 64-bit"), cppcheck::Platform::Type::Win64);
|
||||
}
|
||||
|
||||
int Platforms::getCount() const
|
||||
|
@ -48,7 +48,7 @@ int Platforms::getCount() const
|
|||
return mPlatforms.count();
|
||||
}
|
||||
|
||||
Platform& Platforms::get(cppcheck::Platform::PlatformType platform)
|
||||
Platform& Platforms::get(cppcheck::Platform::Type platform)
|
||||
{
|
||||
QList<Platform>::iterator iter = mPlatforms.begin();
|
||||
while (iter != mPlatforms.end()) {
|
||||
|
|
|
@ -35,7 +35,7 @@ class QAction;
|
|||
*/
|
||||
struct Platform {
|
||||
QString mTitle; /**< Text visible in the GUI. */
|
||||
cppcheck::Platform::PlatformType mType; /**< Type in the core. */
|
||||
cppcheck::Platform::Type mType; /**< Type in the core. */
|
||||
QAction *mActMainWindow; /**< Pointer to main window action item. */
|
||||
};
|
||||
|
||||
|
@ -47,10 +47,10 @@ class Platforms : public QObject {
|
|||
|
||||
public:
|
||||
explicit Platforms(QObject *parent = nullptr);
|
||||
void add(const QString &title, cppcheck::Platform::PlatformType platform);
|
||||
void add(const QString &title, cppcheck::Platform::Type platform);
|
||||
int getCount() const;
|
||||
void init();
|
||||
Platform& get(cppcheck::Platform::PlatformType platform);
|
||||
Platform& get(cppcheck::Platform::Type platform);
|
||||
|
||||
QList<Platform> mPlatforms;
|
||||
};
|
||||
|
|
|
@ -159,7 +159,7 @@ public:
|
|||
|
||||
/**
|
||||
* @brief Get platform.
|
||||
* @return Current platform. If it ends with .xml then it is a file. Otherwise it must match one of the return values from @sa cppcheck::Platform::platformString() ("win32A", "unix32", ..)
|
||||
* @return Current platform. If it ends with .xml then it is a file. Otherwise it must match one of the return values from @sa cppcheck::Platform::toString() ("win32A", "unix32", ..)
|
||||
*/
|
||||
QString getPlatform() const {
|
||||
return mPlatform;
|
||||
|
|
|
@ -61,13 +61,13 @@ static QStringList getPaths(const QListWidget *list)
|
|||
}
|
||||
|
||||
/** Platforms shown in the platform combobox */
|
||||
static const cppcheck::Platform::PlatformType builtinPlatforms[] = {
|
||||
cppcheck::Platform::Native,
|
||||
cppcheck::Platform::Win32A,
|
||||
cppcheck::Platform::Win32W,
|
||||
cppcheck::Platform::Win64,
|
||||
cppcheck::Platform::Unix32,
|
||||
cppcheck::Platform::Unix64
|
||||
static const cppcheck::Platform::Type builtinPlatforms[] = {
|
||||
cppcheck::Platform::Type::Native,
|
||||
cppcheck::Platform::Type::Win32A,
|
||||
cppcheck::Platform::Type::Win32W,
|
||||
cppcheck::Platform::Type::Win64,
|
||||
cppcheck::Platform::Type::Unix32,
|
||||
cppcheck::Platform::Type::Unix64
|
||||
};
|
||||
|
||||
static const int numberOfBuiltinPlatforms = sizeof(builtinPlatforms) / sizeof(builtinPlatforms[0]);
|
||||
|
@ -174,7 +174,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi
|
|||
|
||||
// Platforms..
|
||||
Platforms platforms;
|
||||
for (const cppcheck::Platform::PlatformType builtinPlatform : builtinPlatforms)
|
||||
for (const cppcheck::Platform::Type builtinPlatform : builtinPlatforms)
|
||||
mUI->mComboBoxPlatform->addItem(platforms.get(builtinPlatform).mTitle);
|
||||
QStringList platformFiles;
|
||||
for (QString sp : searchPaths) {
|
||||
|
@ -188,7 +188,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi
|
|||
const QString platformFile = item.fileName();
|
||||
|
||||
cppcheck::Platform plat2;
|
||||
if (!plat2.loadPlatformFile(applicationFilePath.toStdString().c_str(), platformFile.toStdString()))
|
||||
if (!plat2.loadFromFile(applicationFilePath.toStdString().c_str(), platformFile.toStdString()))
|
||||
continue;
|
||||
|
||||
if (platformFiles.indexOf(platformFile) == -1)
|
||||
|
@ -316,8 +316,8 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
|
|||
} else {
|
||||
int i;
|
||||
for (i = 0; i < numberOfBuiltinPlatforms; ++i) {
|
||||
const cppcheck::Platform::PlatformType p = builtinPlatforms[i];
|
||||
if (platform == cppcheck::Platform::platformString(p))
|
||||
const cppcheck::Platform::Type p = builtinPlatforms[i];
|
||||
if (platform == cppcheck::Platform::toString(p))
|
||||
break;
|
||||
}
|
||||
if (i < numberOfBuiltinPlatforms)
|
||||
|
@ -416,7 +416,7 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
|
|||
else {
|
||||
const int i = mUI->mComboBoxPlatform->currentIndex();
|
||||
if (i < numberOfBuiltinPlatforms)
|
||||
projectFile->setPlatform(cppcheck::Platform::platformString(builtinPlatforms[i]));
|
||||
projectFile->setPlatform(cppcheck::Platform::toString(builtinPlatforms[i]));
|
||||
else
|
||||
projectFile->setPlatform(QString());
|
||||
}
|
||||
|
|
|
@ -216,7 +216,7 @@ static bool getDimensionsEtc(const Token * const arrayToken, const Settings *set
|
|||
Dimension dim;
|
||||
dim.known = value->isKnown();
|
||||
dim.tok = nullptr;
|
||||
const int typeSize = array->valueType()->typeSize(*settings, array->valueType()->pointer > 1);
|
||||
const int typeSize = array->valueType()->typeSize(settings->platform, array->valueType()->pointer > 1);
|
||||
if (typeSize == 0)
|
||||
return false;
|
||||
dim.num = value->intvalue / typeSize;
|
||||
|
@ -564,11 +564,11 @@ ValueFlow::Value CheckBufferOverrun::getBufferSize(const Token *bufTok) const
|
|||
v.valueType = ValueFlow::Value::ValueType::BUFFER_SIZE;
|
||||
|
||||
if (var->isPointerArray())
|
||||
v.intvalue = dim * mSettings->sizeof_pointer;
|
||||
v.intvalue = dim * mSettings->platform.sizeof_pointer;
|
||||
else if (var->isPointer())
|
||||
return ValueFlow::Value(-1);
|
||||
else {
|
||||
const MathLib::bigint typeSize = bufTok->valueType()->typeSize(*mSettings);
|
||||
const MathLib::bigint typeSize = bufTok->valueType()->typeSize(mSettings->platform);
|
||||
v.intvalue = dim * typeSize;
|
||||
}
|
||||
|
||||
|
@ -885,7 +885,7 @@ bool CheckBufferOverrun::isCtuUnsafeBufferUsage(const Check *check, const Token
|
|||
const CheckBufferOverrun *c = dynamic_cast<const CheckBufferOverrun *>(check);
|
||||
if (!c)
|
||||
return false;
|
||||
if (!argtok->valueType() || argtok->valueType()->typeSize(*c->mSettings) == 0)
|
||||
if (!argtok->valueType() || argtok->valueType()->typeSize(c->mSettings->platform) == 0)
|
||||
return false;
|
||||
const Token *indexTok = nullptr;
|
||||
if (type == 1 && Token::Match(argtok, "%name% [") && argtok->astParent() == argtok->next() && !Token::simpleMatch(argtok->linkAt(1), "] ["))
|
||||
|
@ -898,7 +898,7 @@ bool CheckBufferOverrun::isCtuUnsafeBufferUsage(const Check *check, const Token
|
|||
return false;
|
||||
if (!indexTok->hasKnownIntValue())
|
||||
return false;
|
||||
*offset = indexTok->getKnownIntValue() * argtok->valueType()->typeSize(*c->mSettings);
|
||||
*offset = indexTok->getKnownIntValue() * argtok->valueType()->typeSize(c->mSettings->platform);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1051,7 +1051,7 @@ void CheckBufferOverrun::objectIndex()
|
|||
continue;
|
||||
}
|
||||
if (obj->valueType() && var->valueType() && (obj->isCast() || (mTokenizer->isCPP() && isCPPCast(obj)) || obj->valueType()->pointer)) { // allow cast to a different type
|
||||
const auto varSize = var->valueType()->typeSize(*mSettings);
|
||||
const auto varSize = var->valueType()->typeSize(mSettings->platform);
|
||||
if (varSize == 0)
|
||||
continue;
|
||||
if (obj->valueType()->type != var->valueType()->type) {
|
||||
|
|
|
@ -1860,8 +1860,8 @@ void CheckCondition::checkCompareValueOutOfTypeRange()
|
|||
if (!mSettings->severity.isEnabled(Severity::style))
|
||||
return;
|
||||
|
||||
if (mSettings->platformType == cppcheck::Platform::PlatformType::Native ||
|
||||
mSettings->platformType == cppcheck::Platform::PlatformType::Unspecified)
|
||||
if (mSettings->platform.type == cppcheck::Platform::Type::Native ||
|
||||
mSettings->platform.type == cppcheck::Platform::Type::Unspecified)
|
||||
return;
|
||||
|
||||
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
|
||||
|
@ -1885,19 +1885,19 @@ void CheckCondition::checkCompareValueOutOfTypeRange()
|
|||
bits = 1;
|
||||
break;
|
||||
case ValueType::Type::CHAR:
|
||||
bits = mSettings->char_bit;
|
||||
bits = mSettings->platform.char_bit;
|
||||
break;
|
||||
case ValueType::Type::SHORT:
|
||||
bits = mSettings->short_bit;
|
||||
bits = mSettings->platform.short_bit;
|
||||
break;
|
||||
case ValueType::Type::INT:
|
||||
bits = mSettings->int_bit;
|
||||
bits = mSettings->platform.int_bit;
|
||||
break;
|
||||
case ValueType::Type::LONG:
|
||||
bits = mSettings->long_bit;
|
||||
bits = mSettings->platform.long_bit;
|
||||
break;
|
||||
case ValueType::Type::LONGLONG:
|
||||
bits = mSettings->long_long_bit;
|
||||
bits = mSettings->platform.long_long_bit;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -1910,7 +1910,7 @@ void CheckCondition::checkCompareValueOutOfTypeRange()
|
|||
long long typeMaxValue;
|
||||
if (typeTok->valueType()->sign != ValueType::Sign::SIGNED)
|
||||
typeMaxValue = unsignedTypeMaxValue;
|
||||
else if (bits >= mSettings->int_bit && (!valueTok->valueType() || valueTok->valueType()->sign != ValueType::Sign::SIGNED))
|
||||
else if (bits >= mSettings->platform.int_bit && (!valueTok->valueType() || valueTok->valueType()->sign != ValueType::Sign::SIGNED))
|
||||
typeMaxValue = unsignedTypeMaxValue;
|
||||
else
|
||||
typeMaxValue = unsignedTypeMaxValue / 2;
|
||||
|
|
|
@ -564,8 +564,8 @@ void CheckFunctions::memsetInvalid2ndParam()
|
|||
|
||||
if (printWarning && secondParamTok->isNumber()) { // Check if the second parameter is a literal and is out of range
|
||||
const long long int value = MathLib::toLongNumber(secondParamTok->str());
|
||||
const long long sCharMin = mSettings->signedCharMin();
|
||||
const long long uCharMax = mSettings->unsignedCharMax();
|
||||
const long long sCharMin = mSettings->platform.signedCharMin();
|
||||
const long long uCharMax = mSettings->platform.unsignedCharMax();
|
||||
if (value < sCharMin || value > uCharMax)
|
||||
memsetValueOutOfRangeError(secondParamTok, secondParamTok->str());
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ namespace {
|
|||
|
||||
void CheckIO::checkFileUsage()
|
||||
{
|
||||
const bool windows = mSettings->isWindowsPlatform();
|
||||
const bool windows = mSettings->platform.isWindows();
|
||||
const bool printPortability = mSettings->severity.isEnabled(Severity::portability);
|
||||
const bool printWarnings = mSettings->severity.isEnabled(Severity::warning);
|
||||
|
||||
|
@ -517,7 +517,7 @@ static inline bool typesMatch(const std::string& iToTest, const std::string& iTy
|
|||
void CheckIO::checkWrongPrintfScanfArguments()
|
||||
{
|
||||
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
|
||||
const bool isWindows = mSettings->isWindowsPlatform();
|
||||
const bool isWindows = mSettings->platform.isWindows();
|
||||
|
||||
for (const Scope * scope : symbolDatabase->functionScopes) {
|
||||
for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
|
||||
|
@ -590,7 +590,7 @@ void CheckIO::checkFormatString(const Token * const tok,
|
|||
const bool scan,
|
||||
const bool scanf_s)
|
||||
{
|
||||
const bool isWindows = mSettings->isWindowsPlatform();
|
||||
const bool isWindows = mSettings->platform.isWindows();
|
||||
const bool printWarning = mSettings->severity.isEnabled(Severity::warning);
|
||||
const std::string &formatString = formatStringTok->str();
|
||||
|
||||
|
@ -1483,12 +1483,12 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * arg, const Settings *settings,
|
|||
tempToken->linenr(tok1->linenr());
|
||||
if (tok1->next()->str() == "size") {
|
||||
// size_t is platform dependent
|
||||
if (settings->sizeof_size_t == 8) {
|
||||
if (settings->platform.sizeof_size_t == 8) {
|
||||
tempToken->str("long");
|
||||
if (settings->sizeof_long != 8)
|
||||
if (settings->platform.sizeof_long != 8)
|
||||
tempToken->isLong(true);
|
||||
} else if (settings->sizeof_size_t == 4) {
|
||||
if (settings->sizeof_long == 4) {
|
||||
} else if (settings->platform.sizeof_size_t == 4) {
|
||||
if (settings->platform.sizeof_long == 4) {
|
||||
tempToken->str("long");
|
||||
} else {
|
||||
tempToken->str("int");
|
||||
|
|
|
@ -1051,8 +1051,8 @@ void CheckLeakAutoVar::ret(const Token *tok, VarInfo &varInfo, const bool isEndO
|
|||
const Token* tok3 = tok2->next();
|
||||
while (tok3 && tok3->isCast() && tok3->valueType() &&
|
||||
(tok3->valueType()->pointer ||
|
||||
(tok3->valueType()->typeSize(*mSettings) == 0) ||
|
||||
(tok3->valueType()->typeSize(*mSettings) >= mSettings->sizeof_pointer)))
|
||||
(tok3->valueType()->typeSize(mSettings->platform) == 0) ||
|
||||
(tok3->valueType()->typeSize(mSettings->platform) >= mSettings->platform.sizeof_pointer)))
|
||||
tok3 = tok3->astOperand2() ? tok3->astOperand2() : tok3->astOperand1();
|
||||
if (tok3 && tok3->varId() == varid)
|
||||
tok2 = tok3->next();
|
||||
|
|
|
@ -1160,11 +1160,11 @@ static int estimateSize(const Type* type, const Settings* settings, const Symbol
|
|||
if (var.isStatic())
|
||||
continue;
|
||||
if (var.isPointer() || var.isReference())
|
||||
size = settings->sizeof_pointer;
|
||||
size = settings->platform.sizeof_pointer;
|
||||
else if (var.type() && var.type()->classScope)
|
||||
size = estimateSize(var.type(), settings, symbolDatabase, recursionDepth+1);
|
||||
else if (var.valueType() && var.valueType()->type == ValueType::Type::CONTAINER)
|
||||
size = 3 * settings->sizeof_pointer; // Just guess
|
||||
size = 3 * settings->platform.sizeof_pointer; // Just guess
|
||||
else
|
||||
size = symbolDatabase->sizeOfType(var.typeStartToken());
|
||||
|
||||
|
@ -1303,7 +1303,7 @@ void CheckOther::checkPassByReference()
|
|||
// Ensure that it is a large object.
|
||||
if (!var->type()->classScope)
|
||||
inconclusive = true;
|
||||
else if (estimateSize(var->type(), mSettings, symbolDatabase) <= 2 * mSettings->sizeof_pointer)
|
||||
else if (estimateSize(var->type(), mSettings, symbolDatabase) <= 2 * mSettings->platform.sizeof_pointer)
|
||||
continue;
|
||||
}
|
||||
else
|
||||
|
@ -2951,7 +2951,7 @@ void CheckOther::checkIncompleteArrayFill()
|
|||
if (MathLib::toLongNumber(tok->linkAt(1)->strAt(-1)) == var->dimension(0)) {
|
||||
int size = mTokenizer->sizeOfType(var->typeStartToken());
|
||||
if (size == 0 && var->valueType()->pointer)
|
||||
size = mSettings->sizeof_pointer;
|
||||
size = mSettings->platform.sizeof_pointer;
|
||||
else if (size == 0 && var->type())
|
||||
size = estimateSize(var->type(), mSettings, symbolDatabase);
|
||||
const Token* tok3 = tok->next()->astOperand2()->astOperand1()->astOperand1();
|
||||
|
@ -3115,7 +3115,7 @@ void CheckOther::redundantPointerOpError(const Token* tok, const std::string &va
|
|||
|
||||
void CheckOther::checkInterlockedDecrement()
|
||||
{
|
||||
if (!mSettings->isWindowsPlatform()) {
|
||||
if (!mSettings->platform.isWindows()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ static const struct CWE CWE190(190U); // Integer Overflow or Wraparound
|
|||
void CheckType::checkTooBigBitwiseShift()
|
||||
{
|
||||
// unknown sizeof(int) => can't run this checker
|
||||
if (mSettings->platformType == cppcheck::Platform::Unspecified)
|
||||
if (mSettings->platform.type == cppcheck::Platform::Type::Unspecified)
|
||||
return;
|
||||
|
||||
for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
|
||||
|
@ -84,11 +84,11 @@ void CheckType::checkTooBigBitwiseShift()
|
|||
(lhstype->type == ValueType::Type::WCHAR_T) ||
|
||||
(lhstype->type == ValueType::Type::BOOL) ||
|
||||
(lhstype->type == ValueType::Type::INT))
|
||||
lhsbits = mSettings->int_bit;
|
||||
lhsbits = mSettings->platform.int_bit;
|
||||
else if (lhstype->type == ValueType::Type::LONG)
|
||||
lhsbits = mSettings->long_bit;
|
||||
lhsbits = mSettings->platform.long_bit;
|
||||
else if (lhstype->type == ValueType::Type::LONGLONG)
|
||||
lhsbits = mSettings->long_long_bit;
|
||||
lhsbits = mSettings->platform.long_long_bit;
|
||||
else
|
||||
continue;
|
||||
|
||||
|
@ -160,7 +160,7 @@ void CheckType::tooBigSignedBitwiseShiftError(const Token *tok, int lhsbits, con
|
|||
void CheckType::checkIntegerOverflow()
|
||||
{
|
||||
// unknown sizeof(int) => can't run this checker
|
||||
if (mSettings->platformType == cppcheck::Platform::Unspecified || mSettings->int_bit >= MathLib::bigint_bits)
|
||||
if (mSettings->platform.type == cppcheck::Platform::Type::Unspecified || mSettings->platform.int_bit >= MathLib::bigint_bits)
|
||||
return;
|
||||
|
||||
for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
|
||||
|
@ -174,11 +174,11 @@ void CheckType::checkIntegerOverflow()
|
|||
|
||||
unsigned int bits;
|
||||
if (vt->type == ValueType::Type::INT)
|
||||
bits = mSettings->int_bit;
|
||||
bits = mSettings->platform.int_bit;
|
||||
else if (vt->type == ValueType::Type::LONG)
|
||||
bits = mSettings->long_bit;
|
||||
bits = mSettings->platform.long_bit;
|
||||
else if (vt->type == ValueType::Type::LONGLONG)
|
||||
bits = mSettings->long_long_bit;
|
||||
bits = mSettings->platform.long_long_bit;
|
||||
else
|
||||
continue;
|
||||
|
||||
|
@ -301,7 +301,7 @@ void CheckType::checkLongCast()
|
|||
|
||||
if (tok->astOperand2()->hasKnownIntValue()) {
|
||||
const ValueFlow::Value &v = tok->astOperand2()->values().front();
|
||||
if (mSettings->isIntValue(v.intvalue))
|
||||
if (mSettings->platform.isIntValue(v.intvalue))
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -428,22 +428,22 @@ void CheckType::checkFloatToIntegerOverflow(const Token *tok, const ValueType *v
|
|||
continue;
|
||||
if (!mSettings->isEnabled(&f, false))
|
||||
continue;
|
||||
if (f.floatValue >= std::exp2(mSettings->long_long_bit))
|
||||
if (f.floatValue >= std::exp2(mSettings->platform.long_long_bit))
|
||||
floatToIntegerOverflowError(tok, f);
|
||||
else if ((-f.floatValue) > std::exp2(mSettings->long_long_bit - 1))
|
||||
else if ((-f.floatValue) > std::exp2(mSettings->platform.long_long_bit - 1))
|
||||
floatToIntegerOverflowError(tok, f);
|
||||
else if (mSettings->platformType != cppcheck::Platform::Unspecified) {
|
||||
else if (mSettings->platform.type != cppcheck::Platform::Type::Unspecified) {
|
||||
int bits = 0;
|
||||
if (vtint->type == ValueType::Type::CHAR)
|
||||
bits = mSettings->char_bit;
|
||||
bits = mSettings->platform.char_bit;
|
||||
else if (vtint->type == ValueType::Type::SHORT)
|
||||
bits = mSettings->short_bit;
|
||||
bits = mSettings->platform.short_bit;
|
||||
else if (vtint->type == ValueType::Type::INT)
|
||||
bits = mSettings->int_bit;
|
||||
bits = mSettings->platform.int_bit;
|
||||
else if (vtint->type == ValueType::Type::LONG)
|
||||
bits = mSettings->long_bit;
|
||||
bits = mSettings->platform.long_bit;
|
||||
else if (vtint->type == ValueType::Type::LONGLONG)
|
||||
bits = mSettings->long_long_bit;
|
||||
bits = mSettings->platform.long_long_bit;
|
||||
else
|
||||
continue;
|
||||
if (bits < MathLib::bigint_bits && f.floatValue >= (((MathLib::biguint)1) << bits))
|
||||
|
|
|
@ -1536,7 +1536,7 @@ static void setValues(Tokenizer *tokenizer, SymbolDatabase *symbolDatabase)
|
|||
return v * dim.num;
|
||||
});
|
||||
if (var.valueType())
|
||||
typeSize += mul * var.valueType()->typeSize(*settings, true);
|
||||
typeSize += mul * var.valueType()->typeSize(settings->platform, true);
|
||||
}
|
||||
scope.definedType->sizeOf = typeSize;
|
||||
}
|
||||
|
@ -1544,7 +1544,7 @@ static void setValues(Tokenizer *tokenizer, SymbolDatabase *symbolDatabase)
|
|||
for (Token *tok = const_cast<Token*>(tokenizer->tokens()); tok; tok = tok->next()) {
|
||||
if (Token::simpleMatch(tok, "sizeof (")) {
|
||||
ValueType vt = ValueType::parseDecl(tok->tokAt(2), settings, tokenizer->isCPP());
|
||||
const int sz = vt.typeSize(*settings, true);
|
||||
const int sz = vt.typeSize(settings->platform, true);
|
||||
if (sz <= 0)
|
||||
continue;
|
||||
long long mul = 1;
|
||||
|
|
|
@ -303,13 +303,13 @@ static void createDumpFile(const Settings& settings,
|
|||
fdump << "<?xml version=\"1.0\"?>" << std::endl;
|
||||
fdump << "<dumps" << language << ">" << std::endl;
|
||||
fdump << " <platform"
|
||||
<< " name=\"" << settings.platformString() << '\"'
|
||||
<< " char_bit=\"" << settings.char_bit << '\"'
|
||||
<< " short_bit=\"" << settings.short_bit << '\"'
|
||||
<< " int_bit=\"" << settings.int_bit << '\"'
|
||||
<< " long_bit=\"" << settings.long_bit << '\"'
|
||||
<< " long_long_bit=\"" << settings.long_long_bit << '\"'
|
||||
<< " pointer_bit=\"" << (settings.sizeof_pointer * settings.char_bit) << '\"'
|
||||
<< " name=\"" << settings.platform.toString() << '\"'
|
||||
<< " char_bit=\"" << settings.platform.char_bit << '\"'
|
||||
<< " short_bit=\"" << settings.platform.short_bit << '\"'
|
||||
<< " int_bit=\"" << settings.platform.int_bit << '\"'
|
||||
<< " long_bit=\"" << settings.platform.long_bit << '\"'
|
||||
<< " long_long_bit=\"" << settings.platform.long_long_bit << '\"'
|
||||
<< " pointer_bit=\"" << (settings.platform.sizeof_pointer * settings.platform.char_bit) << '\"'
|
||||
<< "/>\n";
|
||||
}
|
||||
|
||||
|
@ -610,8 +610,8 @@ unsigned int CppCheck::check(const ImportProject::FileSettings &fs)
|
|||
temp.mSettings.standards.setCPP(fs.standard);
|
||||
else if (!fs.standard.empty())
|
||||
temp.mSettings.standards.setC(fs.standard);
|
||||
if (fs.platformType != cppcheck::Platform::Unspecified)
|
||||
temp.mSettings.platform(fs.platformType);
|
||||
if (fs.platformType != cppcheck::Platform::Type::Unspecified)
|
||||
temp.mSettings.platform.set(fs.platformType);
|
||||
if (mSettings.clang) {
|
||||
temp.mSettings.includePaths.insert(temp.mSettings.includePaths.end(), fs.systemIncludePaths.cbegin(), fs.systemIncludePaths.cend());
|
||||
return temp.check(Path::simplifyPath(fs.filename));
|
||||
|
@ -651,7 +651,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
|
|||
for (const std::string &I : mSettings.includePaths)
|
||||
includePaths += " -I" + I;
|
||||
mErrorLogger.reportOut("Includes:" + includePaths);
|
||||
mErrorLogger.reportOut(std::string("Platform:") + mSettings.platformString());
|
||||
mErrorLogger.reportOut(std::string("Platform:") + mSettings.platform.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -365,7 +365,7 @@ CTU::FileInfo *CTU::getFileInfo(const Tokenizer *tokenizer)
|
|||
functionCall.location = FileInfo::Location(tokenizer, tok);
|
||||
functionCall.callArgNr = argnr + 1;
|
||||
functionCall.callArgumentExpression = argtok->expressionString();
|
||||
const auto typeSize = argtok->valueType()->typeSize(*tokenizer->getSettings());
|
||||
const auto typeSize = argtok->valueType()->typeSize(tokenizer->getSettings()->platform);
|
||||
functionCall.callArgValue = typeSize > 0 ? argtok->variable()->dimension(0) * typeSize : -1;
|
||||
functionCall.warning = false;
|
||||
fileInfo->functionCalls.push_back(std::move(functionCall));
|
||||
|
@ -379,7 +379,7 @@ CTU::FileInfo *CTU::getFileInfo(const Tokenizer *tokenizer)
|
|||
functionCall.location = FileInfo::Location(tokenizer, tok);
|
||||
functionCall.callArgNr = argnr + 1;
|
||||
functionCall.callArgumentExpression = argtok->expressionString();
|
||||
functionCall.callArgValue = argtok->astOperand1()->valueType()->typeSize(*tokenizer->getSettings());
|
||||
functionCall.callArgValue = argtok->astOperand1()->valueType()->typeSize(tokenizer->getSettings()->platform);
|
||||
functionCall.warning = false;
|
||||
fileInfo->functionCalls.push_back(std::move(functionCall));
|
||||
}
|
||||
|
|
|
@ -787,9 +787,9 @@ bool ImportProject::importVcxproj(const std::string &filename, std::map<std::str
|
|||
fs.useMfc = useOfMfc;
|
||||
fs.defines = "_WIN32=1";
|
||||
if (p.platform == ProjectConfiguration::Win32)
|
||||
fs.platformType = cppcheck::Platform::Win32W;
|
||||
fs.platformType = cppcheck::Platform::Type::Win32W;
|
||||
else if (p.platform == ProjectConfiguration::x64) {
|
||||
fs.platformType = cppcheck::Platform::Win64;
|
||||
fs.platformType = cppcheck::Platform::Type::Win64;
|
||||
fs.defines += ";_WIN64=1";
|
||||
}
|
||||
std::string additionalIncludePaths;
|
||||
|
@ -1284,7 +1284,7 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
|
|||
return true;
|
||||
}
|
||||
|
||||
void ImportProject::selectOneVsConfig(cppcheck::Platform::PlatformType platform)
|
||||
void ImportProject::selectOneVsConfig(cppcheck::Platform::Type platform)
|
||||
{
|
||||
std::set<std::string> filenames;
|
||||
for (std::list<ImportProject::FileSettings>::iterator it = fileSettings.begin(); it != fileSettings.end();) {
|
||||
|
@ -1296,11 +1296,11 @@ void ImportProject::selectOneVsConfig(cppcheck::Platform::PlatformType platform)
|
|||
bool remove = false;
|
||||
if (fs.cfg.compare(0,5,"Debug") != 0)
|
||||
remove = true;
|
||||
if (platform == cppcheck::Platform::Win64 && fs.platformType != platform)
|
||||
if (platform == cppcheck::Platform::Type::Win64 && fs.platformType != platform)
|
||||
remove = true;
|
||||
else if ((platform == cppcheck::Platform::Win32A || platform == cppcheck::Platform::Win32W) && fs.platformType == cppcheck::Platform::Win64)
|
||||
else if ((platform == cppcheck::Platform::Type::Win32A || platform == cppcheck::Platform::Type::Win32W) && fs.platformType == cppcheck::Platform::Type::Win64)
|
||||
remove = true;
|
||||
else if (fs.platformType != cppcheck::Platform::Win64 && platform == cppcheck::Platform::Win64)
|
||||
else if (fs.platformType != cppcheck::Platform::Type::Win64 && platform == cppcheck::Platform::Type::Win64)
|
||||
remove = true;
|
||||
else if (filenames.find(fs.filename) != filenames.end())
|
||||
remove = true;
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
|
||||
/** File settings. Multiple configurations for a file is allowed. */
|
||||
struct CPPCHECKLIB FileSettings {
|
||||
FileSettings() : platformType(cppcheck::Platform::Unspecified), msc(false), useMfc(false) {}
|
||||
FileSettings() : platformType(cppcheck::Platform::Type::Unspecified), msc(false), useMfc(false) {}
|
||||
std::string cfg;
|
||||
std::string filename;
|
||||
std::string defines;
|
||||
|
@ -74,7 +74,7 @@ public:
|
|||
std::list<std::string> includePaths;
|
||||
std::list<std::string> systemIncludePaths;
|
||||
std::string standard;
|
||||
cppcheck::Platform::PlatformType platformType;
|
||||
cppcheck::Platform::Type platformType;
|
||||
bool msc;
|
||||
bool useMfc;
|
||||
|
||||
|
@ -90,7 +90,7 @@ public:
|
|||
ImportProject(const ImportProject&) = default;
|
||||
ImportProject& operator=(const ImportProject&) = default;
|
||||
|
||||
void selectOneVsConfig(cppcheck::Platform::PlatformType platform);
|
||||
void selectOneVsConfig(cppcheck::Platform::Type platform);
|
||||
|
||||
std::list<std::string> getVSConfigs();
|
||||
|
||||
|
|
|
@ -31,21 +31,21 @@ cppcheck::Platform::Platform()
|
|||
{
|
||||
// This assumes the code you are checking is for the same architecture this is compiled on.
|
||||
#if defined(_WIN64)
|
||||
platform(Win64);
|
||||
set(Type::Win64);
|
||||
#elif defined(_WIN32)
|
||||
platform(Win32A);
|
||||
set(Type::Win32A);
|
||||
#else
|
||||
platform(Native);
|
||||
set(Type::Native);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool cppcheck::Platform::platform(cppcheck::Platform::PlatformType type)
|
||||
bool cppcheck::Platform::set(Type t)
|
||||
{
|
||||
switch (type) {
|
||||
case Unspecified: // unknown type sizes (sizes etc are set but are not known)
|
||||
case Native: // same as system this code was compile on
|
||||
platformType = type;
|
||||
switch (t) {
|
||||
case Type::Unspecified: // unknown type sizes (sizes etc are set but are not known)
|
||||
case Type::Native: // same as system this code was compile on
|
||||
type = t;
|
||||
sizeof_bool = sizeof(bool);
|
||||
sizeof_short = sizeof(short);
|
||||
sizeof_int = sizeof(int);
|
||||
|
@ -57,7 +57,7 @@ bool cppcheck::Platform::platform(cppcheck::Platform::PlatformType type)
|
|||
sizeof_wchar_t = sizeof(wchar_t);
|
||||
sizeof_size_t = sizeof(std::size_t);
|
||||
sizeof_pointer = sizeof(void *);
|
||||
if (type == Unspecified) {
|
||||
if (type == Type::Unspecified) {
|
||||
defaultSign = '\0';
|
||||
} else {
|
||||
defaultSign = std::numeric_limits<char>::is_signed ? 's' : 'u';
|
||||
|
@ -68,9 +68,9 @@ bool cppcheck::Platform::platform(cppcheck::Platform::PlatformType type)
|
|||
long_bit = char_bit * sizeof_long;
|
||||
long_long_bit = char_bit * sizeof_long_long;
|
||||
return true;
|
||||
case Win32W:
|
||||
case Win32A:
|
||||
platformType = type;
|
||||
case Type::Win32W:
|
||||
case Type::Win32A:
|
||||
type = t;
|
||||
sizeof_bool = 1; // 4 in Visual C++ 4.2
|
||||
sizeof_short = 2;
|
||||
sizeof_int = 4;
|
||||
|
@ -89,8 +89,8 @@ bool cppcheck::Platform::platform(cppcheck::Platform::PlatformType type)
|
|||
long_bit = char_bit * sizeof_long;
|
||||
long_long_bit = char_bit * sizeof_long_long;
|
||||
return true;
|
||||
case Win64:
|
||||
platformType = type;
|
||||
case Type::Win64:
|
||||
type = t;
|
||||
sizeof_bool = 1;
|
||||
sizeof_short = 2;
|
||||
sizeof_int = 4;
|
||||
|
@ -109,8 +109,8 @@ bool cppcheck::Platform::platform(cppcheck::Platform::PlatformType type)
|
|||
long_bit = char_bit * sizeof_long;
|
||||
long_long_bit = char_bit * sizeof_long_long;
|
||||
return true;
|
||||
case Unix32:
|
||||
platformType = type;
|
||||
case Type::Unix32:
|
||||
type = t;
|
||||
sizeof_bool = 1;
|
||||
sizeof_short = 2;
|
||||
sizeof_int = 4;
|
||||
|
@ -129,8 +129,8 @@ bool cppcheck::Platform::platform(cppcheck::Platform::PlatformType type)
|
|||
long_bit = char_bit * sizeof_long;
|
||||
long_long_bit = char_bit * sizeof_long_long;
|
||||
return true;
|
||||
case Unix64:
|
||||
platformType = type;
|
||||
case Type::Unix64:
|
||||
type = t;
|
||||
sizeof_bool = 1;
|
||||
sizeof_short = 2;
|
||||
sizeof_int = 4;
|
||||
|
@ -149,7 +149,7 @@ bool cppcheck::Platform::platform(cppcheck::Platform::PlatformType type)
|
|||
long_bit = char_bit * sizeof_long;
|
||||
long_long_bit = char_bit * sizeof_long_long;
|
||||
return true;
|
||||
case PlatformFile:
|
||||
case Type::File:
|
||||
// sizes are not set.
|
||||
return false;
|
||||
}
|
||||
|
@ -157,22 +157,22 @@ bool cppcheck::Platform::platform(cppcheck::Platform::PlatformType type)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool cppcheck::Platform::platform(const std::string& platformstr, std::string& errstr, const std::vector<std::string>& paths, bool verbose)
|
||||
bool cppcheck::Platform::set(const std::string& platformstr, std::string& errstr, const std::vector<std::string>& paths, bool verbose)
|
||||
{
|
||||
if (platformstr == "win32A")
|
||||
platform(Win32A);
|
||||
set(Type::Win32A);
|
||||
else if (platformstr == "win32W")
|
||||
platform(Win32W);
|
||||
set(Type::Win32W);
|
||||
else if (platformstr == "win64")
|
||||
platform(Win64);
|
||||
set(Type::Win64);
|
||||
else if (platformstr == "unix32")
|
||||
platform(Unix32);
|
||||
set(Type::Unix32);
|
||||
else if (platformstr == "unix64")
|
||||
platform(Unix64);
|
||||
set(Type::Unix64);
|
||||
else if (platformstr == "native")
|
||||
platform(Native);
|
||||
set(Type::Native);
|
||||
else if (platformstr == "unspecified")
|
||||
platform(Unspecified);
|
||||
set(Type::Unspecified);
|
||||
else if (paths.empty()) {
|
||||
errstr = "unrecognized platform: '" + platformstr + "' (no lookup).";
|
||||
return false;
|
||||
|
@ -182,7 +182,7 @@ bool cppcheck::Platform::platform(const std::string& platformstr, std::string& e
|
|||
for (const std::string& path : paths) {
|
||||
if (verbose)
|
||||
std::cout << "looking for platform '" + platformstr + "' in '" + path + "'" << std::endl;
|
||||
if (loadPlatformFile(path.c_str(), platformstr, verbose)) {
|
||||
if (loadFromFile(path.c_str(), platformstr, verbose)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ bool cppcheck::Platform::platform(const std::string& platformstr, std::string& e
|
|||
return true;
|
||||
}
|
||||
|
||||
bool cppcheck::Platform::loadPlatformFile(const char exename[], const std::string &filename, bool verbose)
|
||||
bool cppcheck::Platform::loadFromFile(const char exename[], const std::string &filename, bool verbose)
|
||||
{
|
||||
// TODO: only append .xml if missing
|
||||
// TODO: use native separators
|
||||
|
@ -297,6 +297,6 @@ bool cppcheck::Platform::loadFromXmlDocument(const tinyxml2::XMLDocument *doc)
|
|||
long_bit = char_bit * sizeof_long;
|
||||
long_long_bit = char_bit * sizeof_long_long;
|
||||
|
||||
platformType = PlatformFile;
|
||||
type = Type::File;
|
||||
return !error;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,6 @@ namespace cppcheck {
|
|||
}
|
||||
public:
|
||||
Platform();
|
||||
virtual ~Platform() {}
|
||||
|
||||
bool isIntValue(long long value) const {
|
||||
return value >= min_value(int_bit) && value <= max_value(int_bit);
|
||||
|
@ -101,7 +100,7 @@ namespace cppcheck {
|
|||
|
||||
char defaultSign; // unsigned:'u', signed:'s', unknown:'\0'
|
||||
|
||||
enum PlatformType {
|
||||
enum Type {
|
||||
Unspecified, // No platform specified
|
||||
Native, // whatever system this code was compiled on
|
||||
Win32A,
|
||||
|
@ -109,17 +108,17 @@ namespace cppcheck {
|
|||
Win64,
|
||||
Unix32,
|
||||
Unix64,
|
||||
PlatformFile
|
||||
File
|
||||
};
|
||||
|
||||
/** platform type */
|
||||
PlatformType platformType;
|
||||
Type type;
|
||||
|
||||
/** set the platform type for predefined platforms - deprecated use platform(const std::string&) instead */
|
||||
bool platform(PlatformType type);
|
||||
/** set the platform type for predefined platforms - deprecated use set(const std::string&, std::string&) instead */
|
||||
bool set(Type t);
|
||||
|
||||
/** set the platform type */
|
||||
bool platform(const std::string& platformstr, std::string& errstr, const std::vector<std::string>& paths = {}, bool verbose = false);
|
||||
bool set(const std::string& platformstr, std::string& errstr, const std::vector<std::string>& paths = {}, bool verbose = false);
|
||||
|
||||
/**
|
||||
* load platform file
|
||||
|
@ -128,7 +127,7 @@ namespace cppcheck {
|
|||
* @param verbose log verbose information about the lookup
|
||||
* @return returns true if file was loaded successfully
|
||||
*/
|
||||
bool loadPlatformFile(const char exename[], const std::string &filename, bool verbose = false);
|
||||
bool loadFromFile(const char exename[], const std::string &filename, bool verbose = false);
|
||||
|
||||
/** load platform from xml document, primarily for testing */
|
||||
bool loadFromXmlDocument(const tinyxml2::XMLDocument *doc);
|
||||
|
@ -137,33 +136,33 @@ namespace cppcheck {
|
|||
* @brief Returns true if platform type is Windows
|
||||
* @return true if Windows platform type.
|
||||
*/
|
||||
bool isWindowsPlatform() const {
|
||||
return platformType == Win32A ||
|
||||
platformType == Win32W ||
|
||||
platformType == Win64;
|
||||
bool isWindows() const {
|
||||
return type == Type::Win32A ||
|
||||
type == Type::Win32W ||
|
||||
type == Type::Win64;
|
||||
}
|
||||
|
||||
const char *platformString() const {
|
||||
return platformString(platformType);
|
||||
const char *toString() const {
|
||||
return toString(type);
|
||||
}
|
||||
|
||||
static const char *platformString(PlatformType pt) {
|
||||
static const char *toString(Type pt) {
|
||||
switch (pt) {
|
||||
case Unspecified:
|
||||
case Type::Unspecified:
|
||||
return "unspecified";
|
||||
case Native:
|
||||
case Type::Native:
|
||||
return "native";
|
||||
case Win32A:
|
||||
case Type::Win32A:
|
||||
return "win32A";
|
||||
case Win32W:
|
||||
case Type::Win32W:
|
||||
return "win32W";
|
||||
case Win64:
|
||||
case Type::Win64:
|
||||
return "win64";
|
||||
case Unix32:
|
||||
case Type::Unix32:
|
||||
return "unix32";
|
||||
case Unix64:
|
||||
case Type::Unix64:
|
||||
return "unix64";
|
||||
case PlatformFile:
|
||||
case Type::File:
|
||||
return "platformFile";
|
||||
default:
|
||||
throw std::runtime_error("unknown platform");
|
||||
|
|
|
@ -691,22 +691,22 @@ void Preprocessor::removeComments()
|
|||
|
||||
void Preprocessor::setPlatformInfo(simplecpp::TokenList *tokens) const
|
||||
{
|
||||
tokens->sizeOfType["bool"] = mSettings.sizeof_bool;
|
||||
tokens->sizeOfType["short"] = mSettings.sizeof_short;
|
||||
tokens->sizeOfType["int"] = mSettings.sizeof_int;
|
||||
tokens->sizeOfType["long"] = mSettings.sizeof_long;
|
||||
tokens->sizeOfType["long long"] = mSettings.sizeof_long_long;
|
||||
tokens->sizeOfType["float"] = mSettings.sizeof_float;
|
||||
tokens->sizeOfType["double"] = mSettings.sizeof_double;
|
||||
tokens->sizeOfType["long double"] = mSettings.sizeof_long_double;
|
||||
tokens->sizeOfType["bool *"] = mSettings.sizeof_pointer;
|
||||
tokens->sizeOfType["short *"] = mSettings.sizeof_pointer;
|
||||
tokens->sizeOfType["int *"] = mSettings.sizeof_pointer;
|
||||
tokens->sizeOfType["long *"] = mSettings.sizeof_pointer;
|
||||
tokens->sizeOfType["long long *"] = mSettings.sizeof_pointer;
|
||||
tokens->sizeOfType["float *"] = mSettings.sizeof_pointer;
|
||||
tokens->sizeOfType["double *"] = mSettings.sizeof_pointer;
|
||||
tokens->sizeOfType["long double *"] = mSettings.sizeof_pointer;
|
||||
tokens->sizeOfType["bool"] = mSettings.platform.sizeof_bool;
|
||||
tokens->sizeOfType["short"] = mSettings.platform.sizeof_short;
|
||||
tokens->sizeOfType["int"] = mSettings.platform.sizeof_int;
|
||||
tokens->sizeOfType["long"] = mSettings.platform.sizeof_long;
|
||||
tokens->sizeOfType["long long"] = mSettings.platform.sizeof_long_long;
|
||||
tokens->sizeOfType["float"] = mSettings.platform.sizeof_float;
|
||||
tokens->sizeOfType["double"] = mSettings.platform.sizeof_double;
|
||||
tokens->sizeOfType["long double"] = mSettings.platform.sizeof_long_double;
|
||||
tokens->sizeOfType["bool *"] = mSettings.platform.sizeof_pointer;
|
||||
tokens->sizeOfType["short *"] = mSettings.platform.sizeof_pointer;
|
||||
tokens->sizeOfType["int *"] = mSettings.platform.sizeof_pointer;
|
||||
tokens->sizeOfType["long *"] = mSettings.platform.sizeof_pointer;
|
||||
tokens->sizeOfType["long long *"] = mSettings.platform.sizeof_pointer;
|
||||
tokens->sizeOfType["float *"] = mSettings.platform.sizeof_pointer;
|
||||
tokens->sizeOfType["double *"] = mSettings.platform.sizeof_pointer;
|
||||
tokens->sizeOfType["long double *"] = mSettings.platform.sizeof_pointer;
|
||||
}
|
||||
|
||||
simplecpp::TokenList Preprocessor::preprocess(const simplecpp::TokenList &tokens1, const std::string &cfg, std::vector<std::string> &files, bool throwError)
|
||||
|
|
|
@ -96,7 +96,7 @@ public:
|
|||
* to pass individual values to functions or constructors now or in the
|
||||
* future when we might have even more detailed settings.
|
||||
*/
|
||||
class CPPCHECKLIB Settings : public cppcheck::Platform {
|
||||
class CPPCHECKLIB Settings {
|
||||
private:
|
||||
|
||||
/** @brief terminate checking */
|
||||
|
@ -249,6 +249,8 @@ public:
|
|||
/** @brief write results (--output-file=<file>) */
|
||||
std::string outputFile;
|
||||
|
||||
cppcheck::Platform platform;
|
||||
|
||||
/** @brief Experimental: --performance-valueflow-max-time=T */
|
||||
int performanceValueFlowMaxTime;
|
||||
|
||||
|
|
|
@ -59,9 +59,9 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
|||
|
||||
mIsCpp = isCPP();
|
||||
|
||||
if (mSettings->defaultSign == 's' || mSettings->defaultSign == 'S')
|
||||
if (mSettings->platform.defaultSign == 's' || mSettings->platform.defaultSign == 'S')
|
||||
mDefaultSignedness = ValueType::SIGNED;
|
||||
else if (mSettings->defaultSign == 'u' || mSettings->defaultSign == 'U')
|
||||
else if (mSettings->platform.defaultSign == 'u' || mSettings->platform.defaultSign == 'U')
|
||||
mDefaultSignedness = ValueType::UNSIGNED;
|
||||
else
|
||||
mDefaultSignedness = ValueType::UNKNOWN_SIGN;
|
||||
|
@ -1701,19 +1701,19 @@ void SymbolDatabase::setArrayDimensionsUsingValueFlow()
|
|||
int bits = 0;
|
||||
switch (dimension.tok->valueType()->type) {
|
||||
case ValueType::Type::CHAR:
|
||||
bits = mSettings->char_bit;
|
||||
bits = mSettings->platform.char_bit;
|
||||
break;
|
||||
case ValueType::Type::SHORT:
|
||||
bits = mSettings->short_bit;
|
||||
bits = mSettings->platform.short_bit;
|
||||
break;
|
||||
case ValueType::Type::INT:
|
||||
bits = mSettings->int_bit;
|
||||
bits = mSettings->platform.int_bit;
|
||||
break;
|
||||
case ValueType::Type::LONG:
|
||||
bits = mSettings->long_bit;
|
||||
bits = mSettings->platform.long_bit;
|
||||
break;
|
||||
case ValueType::Type::LONGLONG:
|
||||
bits = mSettings->long_long_bit;
|
||||
bits = mSettings->platform.long_long_bit;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -6020,7 +6020,7 @@ nonneg int SymbolDatabase::sizeOfType(const Token *type) const
|
|||
int size = mTokenizer->sizeOfType(type);
|
||||
|
||||
if (size == 0 && type->type() && type->type()->isEnumType() && type->type()->classScope) {
|
||||
size = mSettings->sizeof_int;
|
||||
size = mSettings->platform.sizeof_int;
|
||||
const Token * enum_type = type->type()->classScope->enumType;
|
||||
if (enum_type)
|
||||
size = mTokenizer->sizeOfType(enum_type);
|
||||
|
@ -6828,18 +6828,18 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
|
|||
pos -= 2;
|
||||
} else break;
|
||||
}
|
||||
if (mSettings->platformType != cppcheck::Platform::Unspecified) {
|
||||
if (type <= ValueType::Type::INT && mSettings->isIntValue(unsignedSuffix ? (value >> 1) : value))
|
||||
if (mSettings->platform.type != cppcheck::Platform::Type::Unspecified) {
|
||||
if (type <= ValueType::Type::INT && mSettings->platform.isIntValue(unsignedSuffix ? (value >> 1) : value))
|
||||
type = ValueType::Type::INT;
|
||||
else if (type <= ValueType::Type::INT && !MathLib::isDec(tokStr) && mSettings->isIntValue(value >> 2)) {
|
||||
else if (type <= ValueType::Type::INT && !MathLib::isDec(tokStr) && mSettings->platform.isIntValue(value >> 2)) {
|
||||
type = ValueType::Type::INT;
|
||||
sign = ValueType::Sign::UNSIGNED;
|
||||
} else if (type <= ValueType::Type::LONG && mSettings->isLongValue(unsignedSuffix ? (value >> 1) : value))
|
||||
} else if (type <= ValueType::Type::LONG && mSettings->platform.isLongValue(unsignedSuffix ? (value >> 1) : value))
|
||||
type = ValueType::Type::LONG;
|
||||
else if (type <= ValueType::Type::LONG && !MathLib::isDec(tokStr) && mSettings->isLongValue(value >> 2)) {
|
||||
else if (type <= ValueType::Type::LONG && !MathLib::isDec(tokStr) && mSettings->platform.isLongValue(value >> 2)) {
|
||||
type = ValueType::Type::LONG;
|
||||
sign = ValueType::Sign::UNSIGNED;
|
||||
} else if (mSettings->isLongLongValue(unsignedSuffix ? (value >> 1) : value))
|
||||
} else if (mSettings->platform.isLongLongValue(unsignedSuffix ? (value >> 1) : value))
|
||||
type = ValueType::Type::LONGLONG;
|
||||
else {
|
||||
type = ValueType::Type::LONGLONG;
|
||||
|
@ -6919,7 +6919,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
|
|||
|
||||
else if (Token::simpleMatch(tok->previous(), "sizeof (")) {
|
||||
ValueType valuetype(ValueType::Sign::UNSIGNED, ValueType::Type::LONG, 0U);
|
||||
if (mSettings->platformType == cppcheck::Platform::Win64)
|
||||
if (mSettings->platform.type == cppcheck::Platform::Type::Win64)
|
||||
valuetype.type = ValueType::Type::LONGLONG;
|
||||
|
||||
valuetype.originalTypeName = "size_t";
|
||||
|
@ -7185,7 +7185,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
|
|||
ValueType ValueType::parseDecl(const Token *type, const Settings *settings, bool isCpp)
|
||||
{
|
||||
ValueType vt;
|
||||
parsedecl(type, &vt, settings->defaultSign == 'u' ? Sign::UNSIGNED : Sign::SIGNED, settings, isCpp);
|
||||
parsedecl(type, &vt, settings->platform.defaultSign == 'u' ? Sign::UNSIGNED : Sign::SIGNED, settings, isCpp);
|
||||
return vt;
|
||||
}
|
||||
|
||||
|
@ -7218,13 +7218,13 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings *sett
|
|||
if (podtype && (podtype->sign == 's' || podtype->sign == 'u')) {
|
||||
if (podtype->size == 1)
|
||||
type = ValueType::Type::CHAR;
|
||||
else if (podtype->size == settings->sizeof_int)
|
||||
else if (podtype->size == settings->platform.sizeof_int)
|
||||
type = ValueType::Type::INT;
|
||||
else if (podtype->size == settings->sizeof_short)
|
||||
else if (podtype->size == settings->platform.sizeof_short)
|
||||
type = ValueType::Type::SHORT;
|
||||
else if (podtype->size == settings->sizeof_long)
|
||||
else if (podtype->size == settings->platform.sizeof_long)
|
||||
type = ValueType::Type::LONG;
|
||||
else if (podtype->size == settings->sizeof_long_long)
|
||||
else if (podtype->size == settings->platform.sizeof_long_long)
|
||||
type = ValueType::Type::LONGLONG;
|
||||
else if (podtype->stdtype == Library::PodType::Type::BOOL)
|
||||
type = ValueType::Type::BOOL;
|
||||
|
@ -7248,7 +7248,7 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings *sett
|
|||
return true;
|
||||
}
|
||||
|
||||
const Library::PlatformType *platformType = settings->library.platform_type(typestr, settings->platformString());
|
||||
const Library::PlatformType *platformType = settings->library.platform_type(typestr, settings->platform.toString());
|
||||
if (platformType) {
|
||||
if (platformType->mType == "char")
|
||||
type = ValueType::Type::CHAR;
|
||||
|
@ -7274,11 +7274,11 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings *sett
|
|||
} else if (!podtype && (typestr == "size_t" || typestr == "std::size_t")) {
|
||||
originalTypeName = "size_t";
|
||||
sign = ValueType::UNSIGNED;
|
||||
if (settings->sizeof_size_t == settings->sizeof_long)
|
||||
if (settings->platform.sizeof_size_t == settings->platform.sizeof_long)
|
||||
type = ValueType::Type::LONG;
|
||||
else if (settings->sizeof_size_t == settings->sizeof_long_long)
|
||||
else if (settings->platform.sizeof_size_t == settings->platform.sizeof_long_long)
|
||||
type = ValueType::Type::LONGLONG;
|
||||
else if (settings->sizeof_size_t == settings->sizeof_int)
|
||||
else if (settings->platform.sizeof_size_t == settings->platform.sizeof_int)
|
||||
type = ValueType::Type::INT;
|
||||
else
|
||||
type = ValueType::Type::UNKNOWN_INT;
|
||||
|
|
|
@ -214,9 +214,9 @@ nonneg int Tokenizer::sizeOfType(const Token *type) const
|
|||
return podtype->size;
|
||||
} else if (type->isLong()) {
|
||||
if (type->str() == "double")
|
||||
return mSettings->sizeof_long_double;
|
||||
return mSettings->platform.sizeof_long_double;
|
||||
else if (type->str() == "long")
|
||||
return mSettings->sizeof_long_long;
|
||||
return mSettings->platform.sizeof_long_long;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
|
@ -2873,16 +2873,16 @@ void Tokenizer::fillTypeSizes()
|
|||
{
|
||||
mTypeSize.clear();
|
||||
mTypeSize["char"] = 1;
|
||||
mTypeSize["_Bool"] = mSettings->sizeof_bool;
|
||||
mTypeSize["bool"] = mSettings->sizeof_bool;
|
||||
mTypeSize["short"] = mSettings->sizeof_short;
|
||||
mTypeSize["int"] = mSettings->sizeof_int;
|
||||
mTypeSize["long"] = mSettings->sizeof_long;
|
||||
mTypeSize["float"] = mSettings->sizeof_float;
|
||||
mTypeSize["double"] = mSettings->sizeof_double;
|
||||
mTypeSize["wchar_t"] = mSettings->sizeof_wchar_t;
|
||||
mTypeSize["size_t"] = mSettings->sizeof_size_t;
|
||||
mTypeSize["*"] = mSettings->sizeof_pointer;
|
||||
mTypeSize["_Bool"] = mSettings->platform.sizeof_bool;
|
||||
mTypeSize["bool"] = mSettings->platform.sizeof_bool;
|
||||
mTypeSize["short"] = mSettings->platform.sizeof_short;
|
||||
mTypeSize["int"] = mSettings->platform.sizeof_int;
|
||||
mTypeSize["long"] = mSettings->platform.sizeof_long;
|
||||
mTypeSize["float"] = mSettings->platform.sizeof_float;
|
||||
mTypeSize["double"] = mSettings->platform.sizeof_double;
|
||||
mTypeSize["wchar_t"] = mSettings->platform.sizeof_wchar_t;
|
||||
mTypeSize["size_t"] = mSettings->platform.sizeof_size_t;
|
||||
mTypeSize["*"] = mSettings->platform.sizeof_pointer;
|
||||
}
|
||||
|
||||
void Tokenizer::combineOperators()
|
||||
|
@ -2972,7 +2972,7 @@ void Tokenizer::combineStringAndCharLiterals()
|
|||
|
||||
while (Token::Match(tok->next(), "%str%") || Token::Match(tok->next(), "_T|_TEXT|TEXT ( %str% )")) {
|
||||
if (tok->next()->isName()) {
|
||||
if (!mSettings->isWindowsPlatform())
|
||||
if (!mSettings->platform.isWindows())
|
||||
break;
|
||||
tok->deleteNext(2);
|
||||
tok->next()->deleteNext();
|
||||
|
@ -8123,7 +8123,7 @@ void Tokenizer::simplifyStructDecl()
|
|||
|
||||
void Tokenizer::simplifyCallingConvention()
|
||||
{
|
||||
const bool windows = mSettings->isWindowsPlatform();
|
||||
const bool windows = mSettings->platform.isWindows();
|
||||
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
while (Token::Match(tok, "__cdecl|__stdcall|__fastcall|__thiscall|__clrcall|__syscall|__pascal|__fortran|__far|__near") || (windows && Token::Match(tok, "WINAPI|APIENTRY|CALLBACK"))) {
|
||||
|
@ -8947,7 +8947,7 @@ void Tokenizer::simplifyNamespaceStd()
|
|||
void Tokenizer::simplifyMicrosoftMemoryFunctions()
|
||||
{
|
||||
// skip if not Windows
|
||||
if (!mSettings->isWindowsPlatform())
|
||||
if (!mSettings->platform.isWindows())
|
||||
return;
|
||||
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
|
@ -9042,10 +9042,10 @@ namespace {
|
|||
void Tokenizer::simplifyMicrosoftStringFunctions()
|
||||
{
|
||||
// skip if not Windows
|
||||
if (!mSettings->isWindowsPlatform())
|
||||
if (!mSettings->platform.isWindows())
|
||||
return;
|
||||
|
||||
const bool ansi = mSettings->platformType == cppcheck::Platform::Win32A;
|
||||
const bool ansi = mSettings->platform.type == cppcheck::Platform::Type::Win32A;
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
if (tok->strAt(1) != "(")
|
||||
continue;
|
||||
|
@ -9078,7 +9078,7 @@ void Tokenizer::simplifyMicrosoftStringFunctions()
|
|||
void Tokenizer::simplifyBorland()
|
||||
{
|
||||
// skip if not Windows
|
||||
if (!mSettings->isWindowsPlatform())
|
||||
if (!mSettings->platform.isWindows())
|
||||
return;
|
||||
if (isC())
|
||||
return;
|
||||
|
|
|
@ -1793,11 +1793,11 @@ void TokenList::simplifyPlatformTypes()
|
|||
|
||||
/** @todo This assumes a flat address space. Not true for segmented address space (FAR *). */
|
||||
|
||||
if (mSettings->sizeof_size_t == mSettings->sizeof_long)
|
||||
if (mSettings->platform.sizeof_size_t == mSettings->platform.sizeof_long)
|
||||
type = isLong;
|
||||
else if (mSettings->sizeof_size_t == mSettings->sizeof_long_long)
|
||||
else if (mSettings->platform.sizeof_size_t == mSettings->platform.sizeof_long_long)
|
||||
type = isLongLong;
|
||||
else if (mSettings->sizeof_size_t == mSettings->sizeof_int)
|
||||
else if (mSettings->platform.sizeof_size_t == mSettings->platform.sizeof_int)
|
||||
type = isInt;
|
||||
else
|
||||
return;
|
||||
|
@ -1850,7 +1850,7 @@ void TokenList::simplifyPlatformTypes()
|
|||
}
|
||||
}
|
||||
|
||||
const std::string platform_type(mSettings->platformString());
|
||||
const std::string platform_type(mSettings->platform.toString());
|
||||
|
||||
for (Token *tok = front(); tok; tok = tok->next()) {
|
||||
if (tok->tokType() != Token::eType && tok->tokType() != Token::eName)
|
||||
|
|
|
@ -936,9 +936,9 @@ static void setTokenValue(Token* tok,
|
|||
tok->valueType()->sign == ValueType::Sign::UNSIGNED &&
|
||||
tok->valueType()->pointer == 0) {
|
||||
if (tok->valueType()->type == ValueType::Type::INT)
|
||||
bits = settings->int_bit;
|
||||
bits = settings->platform.int_bit;
|
||||
else if (tok->valueType()->type == ValueType::Type::LONG)
|
||||
bits = settings->long_bit;
|
||||
bits = settings->platform.long_bit;
|
||||
}
|
||||
if (bits > 0 && bits < MathLib::bigint_bits)
|
||||
v.intvalue &= (((MathLib::biguint)1)<<bits) - 1;
|
||||
|
@ -1024,15 +1024,15 @@ static void setTokenValueCast(Token *parent, const ValueType &valueType, const V
|
|||
if (valueType.pointer || value.isImpossible())
|
||||
setTokenValue(parent,value,settings);
|
||||
else if (valueType.type == ValueType::Type::CHAR)
|
||||
setTokenValue(parent, castValue(value, valueType.sign, settings->char_bit), settings);
|
||||
setTokenValue(parent, castValue(value, valueType.sign, settings->platform.char_bit), settings);
|
||||
else if (valueType.type == ValueType::Type::SHORT)
|
||||
setTokenValue(parent, castValue(value, valueType.sign, settings->short_bit), settings);
|
||||
setTokenValue(parent, castValue(value, valueType.sign, settings->platform.short_bit), settings);
|
||||
else if (valueType.type == ValueType::Type::INT)
|
||||
setTokenValue(parent, castValue(value, valueType.sign, settings->int_bit), settings);
|
||||
setTokenValue(parent, castValue(value, valueType.sign, settings->platform.int_bit), settings);
|
||||
else if (valueType.type == ValueType::Type::LONG)
|
||||
setTokenValue(parent, castValue(value, valueType.sign, settings->long_bit), settings);
|
||||
setTokenValue(parent, castValue(value, valueType.sign, settings->platform.long_bit), settings);
|
||||
else if (valueType.type == ValueType::Type::LONGLONG)
|
||||
setTokenValue(parent, castValue(value, valueType.sign, settings->long_long_bit), settings);
|
||||
setTokenValue(parent, castValue(value, valueType.sign, settings->platform.long_long_bit), settings);
|
||||
else if (valueType.isFloat() && isNumeric(value)) {
|
||||
ValueFlow::Value floatValue = value;
|
||||
floatValue.valueType = ValueFlow::Value::ValueType::FLOAT;
|
||||
|
@ -1040,8 +1040,8 @@ static void setTokenValueCast(Token *parent, const ValueType &valueType, const V
|
|||
floatValue.floatValue = value.intvalue;
|
||||
setTokenValue(parent, std::move(floatValue), settings);
|
||||
} else if (value.isIntValue()) {
|
||||
const long long charMax = settings->signedCharMax();
|
||||
const long long charMin = settings->signedCharMin();
|
||||
const long long charMax = settings->platform.signedCharMax();
|
||||
const long long charMin = settings->platform.signedCharMin();
|
||||
if (charMin <= value.intvalue && value.intvalue <= charMax) {
|
||||
// unknown type, but value is small so there should be no truncation etc
|
||||
setTokenValue(parent,value,settings);
|
||||
|
@ -1053,19 +1053,19 @@ static nonneg int getSizeOfType(const Token *typeTok, const Settings *settings)
|
|||
{
|
||||
const ValueType &valueType = ValueType::parseDecl(typeTok, settings, true); // TODO: set isCpp
|
||||
if (valueType.pointer > 0)
|
||||
return settings->sizeof_pointer;
|
||||
return settings->platform.sizeof_pointer;
|
||||
if (valueType.type == ValueType::Type::BOOL || valueType.type == ValueType::Type::CHAR)
|
||||
return 1;
|
||||
if (valueType.type == ValueType::Type::SHORT)
|
||||
return settings->sizeof_short;
|
||||
return settings->platform.sizeof_short;
|
||||
if (valueType.type == ValueType::Type::INT)
|
||||
return settings->sizeof_int;
|
||||
return settings->platform.sizeof_int;
|
||||
if (valueType.type == ValueType::Type::LONG)
|
||||
return settings->sizeof_long;
|
||||
return settings->platform.sizeof_long;
|
||||
if (valueType.type == ValueType::Type::LONGLONG)
|
||||
return settings->sizeof_long_long;
|
||||
return settings->platform.sizeof_long_long;
|
||||
if (valueType.type == ValueType::Type::WCHAR_T)
|
||||
return settings->sizeof_wchar_t;
|
||||
return settings->platform.sizeof_wchar_t;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1073,25 +1073,25 @@ static nonneg int getSizeOfType(const Token *typeTok, const Settings *settings)
|
|||
size_t ValueFlow::getSizeOf(const ValueType &vt, const Settings *settings)
|
||||
{
|
||||
if (vt.pointer)
|
||||
return settings->sizeof_pointer;
|
||||
return settings->platform.sizeof_pointer;
|
||||
if (vt.type == ValueType::Type::CHAR)
|
||||
return 1;
|
||||
if (vt.type == ValueType::Type::SHORT)
|
||||
return settings->sizeof_short;
|
||||
return settings->platform.sizeof_short;
|
||||
if (vt.type == ValueType::Type::WCHAR_T)
|
||||
return settings->sizeof_wchar_t;
|
||||
return settings->platform.sizeof_wchar_t;
|
||||
if (vt.type == ValueType::Type::INT)
|
||||
return settings->sizeof_int;
|
||||
return settings->platform.sizeof_int;
|
||||
if (vt.type == ValueType::Type::LONG)
|
||||
return settings->sizeof_long;
|
||||
return settings->platform.sizeof_long;
|
||||
if (vt.type == ValueType::Type::LONGLONG)
|
||||
return settings->sizeof_long_long;
|
||||
return settings->platform.sizeof_long_long;
|
||||
if (vt.type == ValueType::Type::FLOAT)
|
||||
return settings->sizeof_float;
|
||||
return settings->platform.sizeof_float;
|
||||
if (vt.type == ValueType::Type::DOUBLE)
|
||||
return settings->sizeof_double;
|
||||
return settings->platform.sizeof_double;
|
||||
if (vt.type == ValueType::Type::LONGDOUBLE)
|
||||
return settings->sizeof_long_double;
|
||||
return settings->platform.sizeof_long_double;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1108,7 +1108,7 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings *settings, b
|
|||
const ValueType* vt = tok->valueType();
|
||||
if (vt && vt->sign == ValueType::UNSIGNED && signedValue < 0 && ValueFlow::getSizeOf(*vt, settings) < sizeof(MathLib::bigint)) {
|
||||
MathLib::bigint minValue{}, maxValue{};
|
||||
if (getMinMaxValues(tok->valueType(), *settings, minValue, maxValue))
|
||||
if (getMinMaxValues(tok->valueType(), settings->platform, minValue, maxValue))
|
||||
signedValue += maxValue + 1;
|
||||
}
|
||||
ValueFlow::Value value(signedValue);
|
||||
|
@ -1162,12 +1162,12 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings *settings, b
|
|||
const size_t sz = vt ? ValueFlow::getSizeOf(*vt, settings) : 0;
|
||||
if (sz > 0) {
|
||||
ValueFlow::Value value(sz);
|
||||
if (!tok2->isTemplateArg() && settings->platformType != cppcheck::Platform::Unspecified)
|
||||
if (!tok2->isTemplateArg() && settings->platform.type != cppcheck::Platform::Type::Unspecified)
|
||||
value.setKnown();
|
||||
setTokenValue(tok->next(), std::move(value), settings);
|
||||
}
|
||||
} else if (tok2->enumerator() && tok2->enumerator()->scope) {
|
||||
long long size = settings->sizeof_int;
|
||||
long long size = settings->platform.sizeof_int;
|
||||
const Token * type = tok2->enumerator()->scope->enumType;
|
||||
if (type) {
|
||||
size = getSizeOfType(type, settings);
|
||||
|
@ -1175,12 +1175,12 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings *settings, b
|
|||
tok->linkAt(1);
|
||||
}
|
||||
ValueFlow::Value value(size);
|
||||
if (!tok2->isTemplateArg() && settings->platformType != cppcheck::Platform::Unspecified)
|
||||
if (!tok2->isTemplateArg() && settings->platform.type != cppcheck::Platform::Type::Unspecified)
|
||||
value.setKnown();
|
||||
setTokenValue(tok, value, settings);
|
||||
setTokenValue(tok->next(), std::move(value), settings);
|
||||
} else if (tok2->type() && tok2->type()->isEnumType()) {
|
||||
long long size = settings->sizeof_int;
|
||||
long long size = settings->platform.sizeof_int;
|
||||
if (tok2->type()->classScope) {
|
||||
const Token * type = tok2->type()->classScope->enumType;
|
||||
if (type) {
|
||||
|
@ -1188,7 +1188,7 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings *settings, b
|
|||
}
|
||||
}
|
||||
ValueFlow::Value value(size);
|
||||
if (!tok2->isTemplateArg() && settings->platformType != cppcheck::Platform::Unspecified)
|
||||
if (!tok2->isTemplateArg() && settings->platform.type != cppcheck::Platform::Type::Unspecified)
|
||||
value.setKnown();
|
||||
setTokenValue(tok, value, settings);
|
||||
setTokenValue(tok->next(), std::move(value), settings);
|
||||
|
@ -1205,7 +1205,7 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings *settings, b
|
|||
sz1->variable()->dimensionKnown(0) &&
|
||||
Token::Match(sz2->astOperand2(), "*|[") && Token::Match(sz2->astOperand2()->astOperand1(), "%varid%", varid1)) {
|
||||
ValueFlow::Value value(sz1->variable()->dimension(0));
|
||||
if (!tok2->isTemplateArg() && settings->platformType != cppcheck::Platform::Unspecified)
|
||||
if (!tok2->isTemplateArg() && settings->platform.type != cppcheck::Platform::Type::Unspecified)
|
||||
value.setKnown();
|
||||
setTokenValue(tok->tokAt(4), std::move(value), settings);
|
||||
}
|
||||
|
@ -1216,7 +1216,7 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings *settings, b
|
|||
// find the size of the type
|
||||
size_t size = 0;
|
||||
if (var->isEnumType()) {
|
||||
size = settings->sizeof_int;
|
||||
size = settings->platform.sizeof_int;
|
||||
if (var->type()->classScope && var->type()->classScope->enumType)
|
||||
size = getSizeOfType(var->type()->classScope->enumType, settings);
|
||||
} else if (var->valueType()) {
|
||||
|
@ -1234,7 +1234,7 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings *settings, b
|
|||
}
|
||||
if (size && count > 0) {
|
||||
ValueFlow::Value value(count * size);
|
||||
if (settings->platformType != cppcheck::Platform::Unspecified)
|
||||
if (settings->platform.type != cppcheck::Platform::Type::Unspecified)
|
||||
value.setKnown();
|
||||
setTokenValue(tok, value, settings);
|
||||
setTokenValue(tok->next(), std::move(value), settings);
|
||||
|
@ -1256,9 +1256,9 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings *settings, b
|
|||
else if (tok2->isUtf32())
|
||||
sz = 4;
|
||||
else if (tok2->isLong())
|
||||
sz = settings->sizeof_wchar_t;
|
||||
sz = settings->platform.sizeof_wchar_t;
|
||||
else if ((tok2->isCChar() && !cpp) || (tok2->isCMultiChar()))
|
||||
sz = settings->sizeof_int;
|
||||
sz = settings->platform.sizeof_int;
|
||||
else
|
||||
sz = 1;
|
||||
|
||||
|
@ -1289,7 +1289,7 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings *settings, b
|
|||
}
|
||||
if (sz > 0) {
|
||||
ValueFlow::Value value(sz);
|
||||
if (!tok2->isTemplateArg() && settings->platformType != cppcheck::Platform::Unspecified)
|
||||
if (!tok2->isTemplateArg() && settings->platform.type != cppcheck::Platform::Type::Unspecified)
|
||||
value.setKnown();
|
||||
setTokenValue(tok->next(), std::move(value), settings);
|
||||
}
|
||||
|
@ -1708,11 +1708,11 @@ static void valueFlowRightShift(TokenList *tokenList, const Settings* settings)
|
|||
(tok->astOperand1()->valueType()->type == ValueType::Type::WCHAR_T) ||
|
||||
(tok->astOperand1()->valueType()->type == ValueType::Type::BOOL) ||
|
||||
(tok->astOperand1()->valueType()->type == ValueType::Type::INT))
|
||||
lhsbits = settings->int_bit;
|
||||
lhsbits = settings->platform.int_bit;
|
||||
else if (tok->astOperand1()->valueType()->type == ValueType::Type::LONG)
|
||||
lhsbits = settings->long_bit;
|
||||
lhsbits = settings->platform.long_bit;
|
||||
else if (tok->astOperand1()->valueType()->type == ValueType::Type::LONGLONG)
|
||||
lhsbits = settings->long_long_bit;
|
||||
lhsbits = settings->platform.long_long_bit;
|
||||
else
|
||||
continue;
|
||||
if (rhsvalue >= lhsbits || rhsvalue >= MathLib::bigint_bits || (1ULL << rhsvalue) <= lhsmax)
|
||||
|
@ -8602,7 +8602,7 @@ static void valueFlowDynamicBufferSize(TokenList* tokenlist, SymbolDatabase* sym
|
|||
if (!typeTok || !typeTok->varId())
|
||||
typeTok = newTok->astParent()->previous(); // hack for "int** z = ..."
|
||||
if (typeTok && typeTok->valueType()) {
|
||||
const MathLib::bigint typeSize = typeTok->valueType()->typeSize(*settings, typeTok->valueType()->pointer > 1);
|
||||
const MathLib::bigint typeSize = typeTok->valueType()->typeSize(settings->platform, typeTok->valueType()->pointer > 1);
|
||||
if (typeSize >= 0)
|
||||
sizeValue = numElem * typeSize;
|
||||
}
|
||||
|
@ -8705,7 +8705,7 @@ static bool getMinMaxValues(const std::string &typestr, const Settings *settings
|
|||
typeTokens.simplifyPlatformTypes();
|
||||
typeTokens.simplifyStdType();
|
||||
const ValueType &vt = ValueType::parseDecl(typeTokens.front(), settings, true); // TODO: set isCpp
|
||||
return getMinMaxValues(&vt, *settings, minvalue, maxvalue);
|
||||
return getMinMaxValues(&vt, settings->platform, minvalue, maxvalue);
|
||||
}
|
||||
|
||||
static void valueFlowSafeFunctions(TokenList* tokenlist, SymbolDatabase* symboldatabase, const Settings* settings)
|
||||
|
@ -8718,7 +8718,7 @@ static void valueFlowSafeFunctions(TokenList* tokenlist, SymbolDatabase* symbold
|
|||
continue;
|
||||
|
||||
const bool safe = function->isSafe(settings);
|
||||
const bool all = safe && settings->platformType != cppcheck::Platform::PlatformType::Unspecified;
|
||||
const bool all = safe && settings->platform.type != cppcheck::Platform::Type::Unspecified;
|
||||
|
||||
for (const Variable &arg : function->argumentList) {
|
||||
if (!arg.nameToken() || !arg.valueType())
|
||||
|
@ -8753,7 +8753,7 @@ static void valueFlowSafeFunctions(TokenList* tokenlist, SymbolDatabase* symbold
|
|||
|
||||
if ((!isLow || !isHigh) && all) {
|
||||
MathLib::bigint minValue, maxValue;
|
||||
if (getMinMaxValues(arg.valueType(), *settings, minValue, maxValue)) {
|
||||
if (getMinMaxValues(arg.valueType(), settings->platform, minValue, maxValue)) {
|
||||
if (!isLow)
|
||||
low = minValue;
|
||||
if (!isHigh)
|
||||
|
|
|
@ -170,6 +170,6 @@ extern std::ostringstream output;
|
|||
} \
|
||||
} while (false)
|
||||
|
||||
#define PLATFORM( S, P ) do { std::string errstr; assertEquals(__FILE__, __LINE__, true, S.platform(cppcheck::Platform::platformString(P), errstr, {exename}), errstr); } while (false)
|
||||
#define PLATFORM( P, T ) do { std::string errstr; assertEquals(__FILE__, __LINE__, true, P.set(cppcheck::Platform::toString(T), errstr, {exename}), errstr); } while (false)
|
||||
|
||||
#endif // fixtureH
|
||||
|
|
|
@ -946,7 +946,7 @@ private:
|
|||
|
||||
void array_index_24() {
|
||||
// ticket #1492 and #1539
|
||||
const std::string charMaxPlusOne(settings0.defaultSign == 'u' ? "256" : "128");
|
||||
const std::string charMaxPlusOne(settings0.platform.defaultSign == 'u' ? "256" : "128");
|
||||
check(("void f(char n) {\n"
|
||||
" int a[n];\n" // n <= CHAR_MAX
|
||||
" a[-1] = 0;\n" // negative index
|
||||
|
@ -4078,7 +4078,7 @@ private:
|
|||
"</def>";
|
||||
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||
settings.severity.enable(Severity::warning);
|
||||
settings.sizeof_wchar_t = 4;
|
||||
settings.platform.sizeof_wchar_t = 4;
|
||||
|
||||
check("void f() {\n"
|
||||
" char c[10];\n"
|
||||
|
|
|
@ -34,7 +34,7 @@ private:
|
|||
Settings settings;
|
||||
|
||||
void run() override {
|
||||
PLATFORM(settings, Settings::Unspecified);
|
||||
PLATFORM(settings.platform, cppcheck::Platform::Type::Unspecified);
|
||||
settings.severity.enable(Severity::warning);
|
||||
settings.severity.enable(Severity::portability);
|
||||
|
||||
|
|
|
@ -1053,7 +1053,7 @@ private:
|
|||
settings.clang = true; \
|
||||
{ \
|
||||
std::string errstr; \
|
||||
ASSERT_EQUALS_MSG(true, settings.platform("unix64", errstr, {exename.c_str()}), errstr); \
|
||||
ASSERT_EQUALS_MSG(true, settings.platform.set("unix64", errstr, {exename.c_str()}), errstr); \
|
||||
} \
|
||||
Tokenizer tokenizer(&settings, this); \
|
||||
{ \
|
||||
|
|
|
@ -986,90 +986,90 @@ private:
|
|||
void platformWin64() {
|
||||
REDIRECT;
|
||||
const char * const argv[] = {"cppcheck", "--platform=win64", "file.cpp"};
|
||||
ASSERT(settings.platform(Settings::Unspecified));
|
||||
ASSERT(settings.platform.set(cppcheck::Platform::Type::Unspecified));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(Settings::Win64, settings.platformType);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Win64, settings.platform.type);
|
||||
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
|
||||
}
|
||||
|
||||
void platformWin32A() {
|
||||
REDIRECT;
|
||||
const char * const argv[] = {"cppcheck", "--platform=win32A", "file.cpp"};
|
||||
ASSERT(settings.platform(Settings::Unspecified));
|
||||
ASSERT(settings.platform.set(cppcheck::Platform::Type::Unspecified));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(Settings::Win32A, settings.platformType);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Win32A, settings.platform.type);
|
||||
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
|
||||
}
|
||||
|
||||
void platformWin32W() {
|
||||
REDIRECT;
|
||||
const char * const argv[] = {"cppcheck", "--platform=win32W", "file.cpp"};
|
||||
ASSERT(settings.platform(Settings::Unspecified));
|
||||
ASSERT(settings.platform.set(cppcheck::Platform::Type::Unspecified));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(Settings::Win32W, settings.platformType);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Win32W, settings.platform.type);
|
||||
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
|
||||
}
|
||||
|
||||
void platformUnix32() {
|
||||
REDIRECT;
|
||||
const char * const argv[] = {"cppcheck", "--platform=unix32", "file.cpp"};
|
||||
ASSERT(settings.platform(Settings::Unspecified));
|
||||
ASSERT(settings.platform.set(cppcheck::Platform::Type::Unspecified));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(Settings::Unix32, settings.platformType);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Unix32, settings.platform.type);
|
||||
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
|
||||
}
|
||||
|
||||
void platformUnix32Unsigned() {
|
||||
REDIRECT;
|
||||
const char * const argv[] = {"cppcheck", "--platform=unix32-unsigned", "file.cpp"};
|
||||
ASSERT(settings.platform(Settings::Unspecified));
|
||||
ASSERT(settings.platform.set(cppcheck::Platform::Type::Unspecified));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.platformType == Settings::Unix32);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Unix32, settings.platform.type);
|
||||
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
|
||||
}
|
||||
|
||||
void platformUnix64() {
|
||||
REDIRECT;
|
||||
const char * const argv[] = {"cppcheck", "--platform=unix64", "file.cpp"};
|
||||
ASSERT(settings.platform(Settings::Unspecified));
|
||||
ASSERT(settings.platform.set(cppcheck::Platform::Type::Unspecified));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(Settings::Unix64, settings.platformType);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Unix64, settings.platform.type);
|
||||
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
|
||||
}
|
||||
|
||||
void platformUnix64Unsigned() {
|
||||
REDIRECT;
|
||||
const char * const argv[] = {"cppcheck", "--platform=unix64-unsigned", "file.cpp"};
|
||||
ASSERT(settings.platform(Settings::Unspecified));
|
||||
ASSERT(settings.platform.set(cppcheck::Platform::Type::Unspecified));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT(settings.platformType == Settings::Unix64);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Unix64, settings.platform.type);
|
||||
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
|
||||
}
|
||||
|
||||
void platformNative() {
|
||||
REDIRECT;
|
||||
const char * const argv[] = {"cppcheck", "--platform=native", "file.cpp"};
|
||||
ASSERT(settings.platform(Settings::Unspecified));
|
||||
ASSERT(settings.platform.set(cppcheck::Platform::Type::Unspecified));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(Settings::Native, settings.platformType);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Native, settings.platform.type);
|
||||
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
|
||||
}
|
||||
|
||||
void platformUnspecified() {
|
||||
REDIRECT;
|
||||
const char * const argv[] = {"cppcheck", "--platform=unspecified", "file.cpp"};
|
||||
ASSERT(settings.platform(Settings::Native));
|
||||
ASSERT(settings.platform.set(cppcheck::Platform::Type::Native));
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(Settings::Unspecified, settings.platformType);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Unspecified, settings.platform.type);
|
||||
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
|
||||
}
|
||||
|
||||
void platformPlatformFile() {
|
||||
REDIRECT;
|
||||
const char * const argv[] = {"cppcheck", "--platform=avr8", "file.cpp"};
|
||||
ASSERT(settings.platform(Settings::Unspecified));
|
||||
ASSERT(settings.platform.set(cppcheck::Platform::Type::Unspecified));
|
||||
ASSERT_EQUALS(true, defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(Settings::PlatformFile, settings.platformType);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::File, settings.platform.type);
|
||||
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
|
||||
}
|
||||
|
||||
|
@ -1090,10 +1090,10 @@ private:
|
|||
settings = Settings();
|
||||
ASSERT(defParser.parseFromArgs(2, argv));
|
||||
#if defined(_WIN64)
|
||||
ASSERT_EQUALS(Settings::Win64, settings.platformType);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Win64, settings.platform.type);
|
||||
ASSERT_EQUALS("cppcheck: Windows 64-bit binaries currently default to the 'win64' platform. Starting with Cppcheck 2.13 they will default to 'native' instead. Please specify '--platform=win64' explicitly if you rely on this.\n", GET_REDIRECT_OUTPUT);
|
||||
#elif defined(_WIN32)
|
||||
ASSERT_EQUALS(Settings::Win32A, settings.platformType);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Win32A, settings.platform.type);
|
||||
ASSERT_EQUALS("cppcheck: Windows 32-bit binaries currently default to the 'win32A' platform. Starting with Cppcheck 2.13 they will default to 'native' instead. Please specify '--platform=win32A' explicitly if you rely on this.\n", GET_REDIRECT_OUTPUT);
|
||||
#endif
|
||||
|
||||
|
@ -1108,7 +1108,7 @@ private:
|
|||
const char * const argv[] = {"cppcheck", "--platform=unix64", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.parseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(Settings::Unix64, settings.platformType);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Unix64, settings.platform.type);
|
||||
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
|
||||
|
||||
CmdLineParser::SHOW_DEF_PLATFORM_MSG = false;
|
||||
|
|
|
@ -46,8 +46,8 @@ private:
|
|||
|
||||
void run() override {
|
||||
// known platform..
|
||||
PLATFORM(settings0, cppcheck::Platform::Native);
|
||||
PLATFORM(settings1, cppcheck::Platform::Native);
|
||||
PLATFORM(settings0.platform, cppcheck::Platform::Type::Native);
|
||||
PLATFORM(settings1.platform, cppcheck::Platform::Type::Native);
|
||||
|
||||
LOAD_LIB_2(settings0.library, "qt.cfg");
|
||||
settings0.libraries.emplace_back("qt");
|
||||
|
@ -5615,7 +5615,7 @@ private:
|
|||
void compareOutOfTypeRange() {
|
||||
Settings settingsUnix64;
|
||||
settingsUnix64.severity.enable(Severity::style);
|
||||
PLATFORM(settingsUnix64, cppcheck::Platform::PlatformType::Unix64);
|
||||
PLATFORM(settingsUnix64.platform, cppcheck::Platform::Type::Unix64);
|
||||
|
||||
check("void f(unsigned char c) {\n"
|
||||
" if (c == 256) {}\n"
|
||||
|
|
260
test/testio.cpp
260
test/testio.cpp
|
@ -85,7 +85,7 @@ private:
|
|||
}
|
||||
|
||||
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
void check_(const char* file, int line, const char* code, bool inconclusive = false, bool portability = false, Settings::PlatformType platform = Settings::Unspecified, bool onlyFormatStr = false, bool cpp = true) {
|
||||
void check_(const char* file, int line, const char* code, bool inconclusive = false, bool portability = false, cppcheck::Platform::Type platform = cppcheck::Platform::Type::Unspecified, bool onlyFormatStr = false, bool cpp = true) {
|
||||
// Clear the error buffer..
|
||||
errout.str("");
|
||||
|
||||
|
@ -95,7 +95,7 @@ private:
|
|||
if (portability)
|
||||
settings.severity.enable(Severity::portability);
|
||||
settings.certainty.setEnabled(Certainty::inconclusive, inconclusive);
|
||||
PLATFORM(settings, platform);
|
||||
PLATFORM(settings.platform, platform);
|
||||
|
||||
// Tokenize..
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
|
@ -181,7 +181,7 @@ private:
|
|||
" fread(buffer, 5, 6, f);\n"
|
||||
" rewind(f);\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32W);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Write operation on a file that was opened only for reading.\n", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
|
@ -189,7 +189,7 @@ private:
|
|||
" fread(buffer, 5, 6, f);\n"
|
||||
" rewind(f);\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32A);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Write operation on a file that was opened only for reading.\n", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
|
@ -197,7 +197,7 @@ private:
|
|||
" fread(buffer, 5, 6, f);\n"
|
||||
" rewind(f);\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32W);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Write operation on a file that was opened only for reading.\n", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
|
@ -205,7 +205,7 @@ private:
|
|||
" fread(buffer, 5, 6, f);\n"
|
||||
" rewind(f);\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32W);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Write operation on a file that was opened only for reading.\n", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
|
@ -213,7 +213,7 @@ private:
|
|||
" fread(buffer, 5, 6, f);\n"
|
||||
" rewind(f);\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32A);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Write operation on a file that was opened only for reading.\n", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
|
@ -221,7 +221,7 @@ private:
|
|||
" fread(buffer, 5, 6, f);\n"
|
||||
" rewind(f);\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32W);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Write operation on a file that was opened only for reading.\n", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
|
@ -233,43 +233,43 @@ private:
|
|||
check("void foo(FILE*& f) {\n"
|
||||
" f = _wfopen(name, L\"r+\");\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32W);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
" f = _tfopen(name, _T(\"r+\"));\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32A);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
" f = _tfopen(name, _T(\"r+\"));\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32W);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
" _wfopen_s(&f, name, L\"r+\");\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32W);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
" _tfopen_s(&f, name, _T(\"r+\"));\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32A);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
" _tfopen_s(&f, name, _T(\"r+\"));\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32W);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
" f = tmpfile();\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32W);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// Write mode
|
||||
|
@ -336,37 +336,37 @@ private:
|
|||
check("void foo(FILE*& f) {\n"
|
||||
" f = _wfreopen(name, L\"r\", f);\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32W);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Write operation on a file that was opened only for reading.\n", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
" f = _tfreopen(name, _T(\"r\"), f);\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32A);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Write operation on a file that was opened only for reading.\n", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
" f = _tfreopen(name, _T(\"r\"), f);\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32W);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Write operation on a file that was opened only for reading.\n", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
" f = _wfreopen_s(&f, name, L\"r\", f);\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32W);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Write operation on a file that was opened only for reading.\n", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
" f = _tfreopen_s(&f, name, _T(\"r\"), f);\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32A);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Write operation on a file that was opened only for reading.\n", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
" f = _tfreopen_s(&f, name, _T(\"r\"), f);\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}", false, false, Settings::Win32W);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Write operation on a file that was opened only for reading.\n", errout.str());
|
||||
|
||||
// Crash tests
|
||||
|
@ -824,65 +824,65 @@ private:
|
|||
|
||||
void testFormatStrNoWarn(const char *filename, unsigned int linenr, const char* code,
|
||||
bool cpp = false) {
|
||||
check(code, true, false, Settings::Unix32, true, cpp);
|
||||
check(code, true, false, cppcheck::Platform::Type::Unix32, true, cpp);
|
||||
assertEquals(filename, linenr, emptyString, errout.str());
|
||||
check(code, true, false, Settings::Unix64, true, cpp);
|
||||
check(code, true, false, cppcheck::Platform::Type::Unix64, true, cpp);
|
||||
assertEquals(filename, linenr, emptyString, errout.str());
|
||||
check(code, true, false, Settings::Win32A, true, cpp);
|
||||
check(code, true, false, cppcheck::Platform::Type::Win32A, true, cpp);
|
||||
assertEquals(filename, linenr, emptyString, errout.str());
|
||||
check(code, true, false, Settings::Win64, true, cpp);
|
||||
check(code, true, false, cppcheck::Platform::Type::Win64, true, cpp);
|
||||
assertEquals(filename, linenr, emptyString, errout.str());
|
||||
}
|
||||
|
||||
void testFormatStrWarn(const char *filename, unsigned int linenr,
|
||||
const char* code, const char* testScanfErrString,
|
||||
bool cpp = false) {
|
||||
check(code, true, false, Settings::Unix32, true, cpp);
|
||||
check(code, true, false, cppcheck::Platform::Type::Unix32, true, cpp);
|
||||
assertEquals(filename, linenr, testScanfErrString, errout.str());
|
||||
check(code, true, false, Settings::Unix64, true, cpp);
|
||||
check(code, true, false, cppcheck::Platform::Type::Unix64, true, cpp);
|
||||
assertEquals(filename, linenr, testScanfErrString, errout.str());
|
||||
check(code, true, false, Settings::Win32A, true, cpp);
|
||||
check(code, true, false, cppcheck::Platform::Type::Win32A, true, cpp);
|
||||
assertEquals(filename, linenr, testScanfErrString, errout.str());
|
||||
check(code, true, false, Settings::Win64, true, cpp);
|
||||
check(code, true, false, cppcheck::Platform::Type::Win64, true, cpp);
|
||||
assertEquals(filename, linenr, testScanfErrString, errout.str());
|
||||
}
|
||||
|
||||
void testFormatStrWarnAka(const char *filename, unsigned int linenr,
|
||||
const char* code, const char* testScanfErrAkaString, const char* testScanfErrAkaWin64String,
|
||||
bool cpp = false) {
|
||||
check(code, true, true, Settings::Unix32, true, cpp);
|
||||
check(code, true, true, cppcheck::Platform::Type::Unix32, true, cpp);
|
||||
assertEquals(filename, linenr, testScanfErrAkaString, errout.str());
|
||||
check(code, true, true, Settings::Unix64, true, cpp);
|
||||
check(code, true, true, cppcheck::Platform::Type::Unix64, true, cpp);
|
||||
assertEquals(filename, linenr, testScanfErrAkaString, errout.str());
|
||||
check(code, true, true, Settings::Win32A, true, cpp);
|
||||
check(code, true, true, cppcheck::Platform::Type::Win32A, true, cpp);
|
||||
assertEquals(filename, linenr, testScanfErrAkaString, errout.str());
|
||||
check(code, true, true, Settings::Win64, true, cpp);
|
||||
check(code, true, true, cppcheck::Platform::Type::Win64, true, cpp);
|
||||
assertEquals(filename, linenr, testScanfErrAkaWin64String, errout.str());
|
||||
}
|
||||
|
||||
void testFormatStrWarnAkaWin64(const char *filename, unsigned int linenr,
|
||||
const char* code, const char* testScanfErrAkaWin64String,
|
||||
bool cpp = false) {
|
||||
check(code, true, true, Settings::Unix32, true, cpp);
|
||||
check(code, true, true, cppcheck::Platform::Type::Unix32, true, cpp);
|
||||
assertEquals(filename, linenr, emptyString, errout.str());
|
||||
check(code, true, true, Settings::Unix64, true, cpp);
|
||||
check(code, true, true, cppcheck::Platform::Type::Unix64, true, cpp);
|
||||
assertEquals(filename, linenr, emptyString, errout.str());
|
||||
check(code, true, true, Settings::Win32A, true, cpp);
|
||||
check(code, true, true, cppcheck::Platform::Type::Win32A, true, cpp);
|
||||
assertEquals(filename, linenr, emptyString, errout.str());
|
||||
check(code, true, true, Settings::Win64, true, cpp);
|
||||
check(code, true, true, cppcheck::Platform::Type::Win64, true, cpp);
|
||||
assertEquals(filename, linenr, testScanfErrAkaWin64String, errout.str());
|
||||
}
|
||||
|
||||
void testFormatStrWarnAkaWin32(const char *filename, unsigned int linenr,
|
||||
const char* code, const char* testScanfErrAkaString,
|
||||
bool cpp = false) {
|
||||
check(code, true, true, Settings::Unix32, true, cpp);
|
||||
check(code, true, true, cppcheck::Platform::Type::Unix32, true, cpp);
|
||||
assertEquals(filename, linenr, testScanfErrAkaString, errout.str());
|
||||
check(code, true, true, Settings::Unix64, true, cpp);
|
||||
check(code, true, true, cppcheck::Platform::Type::Unix64, true, cpp);
|
||||
assertEquals(filename, linenr, testScanfErrAkaString, errout.str());
|
||||
check(code, true, true, Settings::Win32A, true, cpp);
|
||||
check(code, true, true, cppcheck::Platform::Type::Win32A, true, cpp);
|
||||
assertEquals(filename, linenr, testScanfErrAkaString, errout.str());
|
||||
check(code, true, true, Settings::Win64, true, cpp);
|
||||
check(code, true, true, cppcheck::Platform::Type::Win64, true, cpp);
|
||||
assertEquals(filename, linenr, emptyString, errout.str());
|
||||
}
|
||||
|
||||
|
@ -2136,13 +2136,13 @@ private:
|
|||
const char* result_win64("[test.cpp:5]: (portability) %zd in format string (no. 1) requires 'ssize_t *' but the argument type is 'size_t * {aka unsigned long long *}'.\n"
|
||||
"[test.cpp:6]: (portability) %zd in format string (no. 1) requires 'ssize_t *' but the argument type is 'ptrdiff_t * {aka signed long long *}'.\n");
|
||||
|
||||
check(code, false, true, Settings::Unix32);
|
||||
check(code, false, true, cppcheck::Platform::Type::Unix32);
|
||||
ASSERT_EQUALS(result, errout.str());
|
||||
check(code, false, true, Settings::Unix64);
|
||||
check(code, false, true, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS(result, errout.str());
|
||||
check(code, false, true, Settings::Win32A);
|
||||
check(code, false, true, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS(result, errout.str());
|
||||
check(code, false, true, Settings::Win64);
|
||||
check(code, false, true, cppcheck::Platform::Type::Win64);
|
||||
ASSERT_EQUALS(result_win64, errout.str());
|
||||
}
|
||||
{
|
||||
|
@ -2532,56 +2532,56 @@ private:
|
|||
check("void foo(size_t s, ptrdiff_t p) {\n"
|
||||
" printf(\"%zd\", s);\n"
|
||||
" printf(\"%tu\", p);\n"
|
||||
"}", false, true, Settings::Unix32);
|
||||
"}", false, true, cppcheck::Platform::Type::Unix32);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long}'.\n"
|
||||
"[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long}'.\n", errout.str());
|
||||
|
||||
check("void foo(std::size_t s, std::ptrdiff_t p) {\n"
|
||||
" printf(\"%zd\", s);\n"
|
||||
" printf(\"%tu\", p);\n"
|
||||
"}", false, true, Settings::Unix32);
|
||||
"}", false, true, cppcheck::Platform::Type::Unix32);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long}'.\n"
|
||||
"[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long}'.\n", errout.str());
|
||||
|
||||
check("void foo(size_t s, ptrdiff_t p) {\n"
|
||||
" printf(\"%zd\", s);\n"
|
||||
" printf(\"%tu\", p);\n"
|
||||
"}", false, true, Settings::Unix64);
|
||||
"}", false, true, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long}'.\n"
|
||||
"[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long}'.\n", errout.str());
|
||||
|
||||
check("void foo(std::size_t s, std::ptrdiff_t p) {\n"
|
||||
" printf(\"%zd\", s);\n"
|
||||
" printf(\"%tu\", p);\n"
|
||||
"}", false, true, Settings::Unix64);
|
||||
"}", false, true, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long}'.\n"
|
||||
"[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long}'.\n", errout.str());
|
||||
|
||||
check("void foo(size_t s, ptrdiff_t p) {\n"
|
||||
" printf(\"%zd\", s);\n"
|
||||
" printf(\"%tu\", p);\n"
|
||||
"}", false, true, Settings::Win32A);
|
||||
"}", false, true, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long}'.\n"
|
||||
"[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long}'.\n", errout.str());
|
||||
|
||||
check("void foo(std::size_t s, std::ptrdiff_t p) {\n"
|
||||
" printf(\"%zd\", s);\n"
|
||||
" printf(\"%tu\", p);\n"
|
||||
"}", false, true, Settings::Win32A);
|
||||
"}", false, true, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long}'.\n"
|
||||
"[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long}'.\n", errout.str());
|
||||
|
||||
check("void foo(size_t s, ptrdiff_t p) {\n"
|
||||
" printf(\"%zd\", s);\n"
|
||||
" printf(\"%tu\", p);\n"
|
||||
"}", false, true, Settings::Win64);
|
||||
"}", false, true, cppcheck::Platform::Type::Win64);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long long}'.\n"
|
||||
"[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long long}'.\n", errout.str());
|
||||
|
||||
check("void foo(std::size_t s, std::ptrdiff_t p) {\n"
|
||||
" printf(\"%zd\", s);\n"
|
||||
" printf(\"%tu\", p);\n"
|
||||
"}", false, true, Settings::Win64);
|
||||
"}", false, true, cppcheck::Platform::Type::Win64);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long long}'.\n"
|
||||
"[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long long}'.\n", errout.str());
|
||||
|
||||
|
@ -2590,7 +2590,7 @@ private:
|
|||
" printf(\"%lu\", um);\n"
|
||||
" printf(\"%llu\", s);\n"
|
||||
" printf(\"%llu\", um);\n"
|
||||
"}", false, true, Settings::Win64);
|
||||
"}", false, true, cppcheck::Platform::Type::Win64);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (portability) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'size_t {aka unsigned long long}'.\n"
|
||||
"[test.cpp:3]: (portability) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'uintmax_t {aka unsigned long long}'.\n"
|
||||
"[test.cpp:4]: (portability) %llu in format string (no. 1) requires 'unsigned long long' but the argument type is 'size_t {aka unsigned long long}'.\n"
|
||||
|
@ -2621,7 +2621,7 @@ private:
|
|||
check("void foo(intmax_t im, ptrdiff_t p) {\n"
|
||||
" printf(\"%lld\", im);\n"
|
||||
" printf(\"%lld\", p);\n"
|
||||
"}", false, true, Settings::Win64);
|
||||
"}", false, true, cppcheck::Platform::Type::Win64);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (portability) %lld in format string (no. 1) requires 'long long' but the argument type is 'intmax_t {aka signed long long}'.\n"
|
||||
"[test.cpp:3]: (portability) %lld in format string (no. 1) requires 'long long' but the argument type is 'ptrdiff_t {aka signed long long}'.\n", errout.str());
|
||||
|
||||
|
@ -2930,7 +2930,7 @@ private:
|
|||
"void foo() {\n"
|
||||
" printf(\"%zu %Iu %d %f\", v.size(), v.size(), v.size(), v.size());\n"
|
||||
" printf(\"%zu %Iu %d %f\", s.size(), s.size(), s.size(), s.size());\n"
|
||||
"}\n", false, true, Settings::Win32A);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\n"
|
||||
"[test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'.\n"
|
||||
"[test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\n"
|
||||
|
@ -2941,7 +2941,7 @@ private:
|
|||
"void foo() {\n"
|
||||
" printf(\"%zu %Iu %d %f\", v.size(), v.size(), v.size(), v.size());\n"
|
||||
" printf(\"%zu %Iu %d %f\", s.size(), s.size(), s.size(), s.size());\n"
|
||||
"}\n", false, true, Settings::Win64);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Win64);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long long}'.\n"
|
||||
"[test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long long}'.\n"
|
||||
"[test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long long}'.\n"
|
||||
|
@ -2952,7 +2952,7 @@ private:
|
|||
"void foo() {\n"
|
||||
" printf(\"%zu %Iu %d %f\", v.size(), v.size(), v.size(), v.size());\n"
|
||||
" printf(\"%zu %Iu %d %f\", s.size(), s.size(), s.size(), s.size());\n"
|
||||
"}\n", false, true, Settings::Unix32);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Unix32);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\n"
|
||||
"[test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'.\n"
|
||||
"[test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\n"
|
||||
|
@ -2963,7 +2963,7 @@ private:
|
|||
"void foo() {\n"
|
||||
" printf(\"%zu %Iu %d %f\", v.size(), v.size(), v.size(), v.size());\n"
|
||||
" printf(\"%zu %Iu %d %f\", s.size(), s.size(), s.size(), s.size());\n"
|
||||
"}\n", false, true, Settings::Unix64);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\n"
|
||||
"[test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'.\n"
|
||||
"[test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\n"
|
||||
|
@ -2974,7 +2974,7 @@ private:
|
|||
"void foo() {\n"
|
||||
" printf(\"%zu %Iu %d %f\", v.size(), v.size(), v.size(), v.size());\n"
|
||||
" printf(\"%zu %Iu %d %f\", s.size(), s.size(), s.size(), s.size());\n"
|
||||
"}\n", false, true, Settings::Unix64);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'size_t {aka unsigned long}'.\n"
|
||||
"[test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'size_t {aka unsigned long}'.\n"
|
||||
"[test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\n"
|
||||
|
@ -2983,14 +2983,14 @@ private:
|
|||
check("class Fred : public std::vector<int> {} v;\n"
|
||||
"void foo() {\n"
|
||||
" printf(\"%d %u %f\", v[0], v[0], v[0]);\n"
|
||||
"}\n", false, true, Settings::Unix64);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'int'.\n"
|
||||
"[test.cpp:3]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'int'.\n", errout.str());
|
||||
|
||||
check("std::string s;\n"
|
||||
"void foo() {\n"
|
||||
" printf(\"%s %p %u %d %f\", s.c_str(), s.c_str(), s.c_str(), s.c_str(), s.c_str());\n"
|
||||
"}\n", false, true, Settings::Unix64);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'const char *'.\n"
|
||||
"[test.cpp:3]: (warning) %d in format string (no. 4) requires 'int' but the argument type is 'const char *'.\n"
|
||||
"[test.cpp:3]: (warning) %f in format string (no. 5) requires 'double' but the argument type is 'const char *'.\n", errout.str());
|
||||
|
@ -3006,7 +3006,7 @@ private:
|
|||
" printf(\"%u %u\", array.size(), s);\n"
|
||||
" printf(\"%lu %lu\", array.size(), s);\n"
|
||||
" printf(\"%llu %llu\", array.size(), s);\n"
|
||||
"}\n", false, true, Settings::Unix64);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS("[test.cpp:8]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'char *'.\n"
|
||||
"[test.cpp:8]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'char *'.\n"
|
||||
"[test.cpp:8]: (warning) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'char *'.\n"
|
||||
|
@ -3030,7 +3030,7 @@ private:
|
|||
"char ca[3];\n"
|
||||
"void foo() {\n"
|
||||
" printf(\"%td %zd %d %d %d %d %d %d %d %d %d %d %d\", pt, pt, b, c, sc, uc, s, us, st, pt, pc, cl, ca);\n"
|
||||
"}\n", false, true, Settings::Unix64);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS("[test.cpp:13]: (portability) %zd in format string (no. 2) requires 'ssize_t' but the argument type is 'ptrdiff_t {aka signed long}'.\n"
|
||||
"[test.cpp:13]: (portability) %d in format string (no. 9) requires 'int' but the argument type is 'size_t {aka unsigned long}'.\n"
|
||||
"[test.cpp:13]: (portability) %d in format string (no. 10) requires 'int' but the argument type is 'ptrdiff_t {aka signed long}'.\n"
|
||||
|
@ -3051,7 +3051,7 @@ private:
|
|||
"char ca[3];\n"
|
||||
"void foo() {\n"
|
||||
" printf(\"%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld\", b, c, sc, uc, s, us, st, pt, pc, cl, ca);\n"
|
||||
"}\n", false, true, Settings::Unix64);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS("[test.cpp:13]: (warning) %ld in format string (no. 1) requires 'long' but the argument type is 'bool'.\n"
|
||||
"[test.cpp:13]: (warning) %ld in format string (no. 2) requires 'long' but the argument type is 'char'.\n"
|
||||
"[test.cpp:13]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'signed char'.\n"
|
||||
|
@ -3078,7 +3078,7 @@ private:
|
|||
"char ca[3];\n"
|
||||
"void foo() {\n"
|
||||
" printf(\"%td %zd %d %d %d %d %d %d %d %d %d\", ptf(), ptf(), bf(), cf(), scf(), ucf(), sf(), usf(), stf(), ptf(), pcf());\n"
|
||||
"}\n", false, true, Settings::Unix64);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS("[test.cpp:13]: (portability) %zd in format string (no. 2) requires 'ssize_t' but the argument type is 'ptrdiff_t {aka signed long}'.\n"
|
||||
"[test.cpp:13]: (portability) %d in format string (no. 9) requires 'int' but the argument type is 'size_t {aka unsigned long}'.\n"
|
||||
"[test.cpp:13]: (portability) %d in format string (no. 10) requires 'int' but the argument type is 'ptrdiff_t {aka signed long}'.\n"
|
||||
|
@ -3097,7 +3097,7 @@ private:
|
|||
"char ca[3];\n"
|
||||
"void foo() {\n"
|
||||
" printf(\"%ld %ld %ld %ld %ld %ld %ld %ld %ld\", bf(), cf(), scf(), ucf(), sf(), usf(), stf(), ptf(), pcf());\n"
|
||||
"}\n", false, true, Settings::Unix64);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS("[test.cpp:13]: (warning) %ld in format string (no. 1) requires 'long' but the argument type is 'bool'.\n"
|
||||
"[test.cpp:13]: (warning) %ld in format string (no. 2) requires 'long' but the argument type is 'char'.\n"
|
||||
"[test.cpp:13]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'signed char'.\n"
|
||||
|
@ -3117,7 +3117,7 @@ private:
|
|||
" printf(\"%p %d\", b[0], b[0]);\n"
|
||||
" printf(\"%p %d\", c[0], c[0]);\n"
|
||||
" printf(\"%p %d\", s.c_str(), s.c_str());\n"
|
||||
"}\n", false, true, Settings::Unix64);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS("[test.cpp:6]: (portability) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'size_t {aka unsigned long}'.\n"
|
||||
"[test.cpp:7]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const int *'.\n"
|
||||
"[test.cpp:8]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const struct A *'.\n"
|
||||
|
@ -3130,7 +3130,7 @@ private:
|
|||
" printf(\"%p %d\", a[0].c_str(), a[0].c_str());\n"
|
||||
" printf(\"%c %p\", b[0], b[0]);\n"
|
||||
" printf(\"%c %p\", s[0], s[0]);\n"
|
||||
"}\n", false, false, Settings::Unix64);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const char *'.\n"
|
||||
"[test.cpp:6]: (warning) %p in format string (no. 2) requires an address but the argument type is 'char'.\n"
|
||||
"[test.cpp:7]: (warning) %p in format string (no. 2) requires an address but the argument type is 'char'.\n", errout.str());
|
||||
|
@ -3142,28 +3142,28 @@ private:
|
|||
"buffer<int> b;\n"
|
||||
"void foo() {\n"
|
||||
" printf(\"%u\", b.size());\n"
|
||||
"}\n", false, true, Settings::Unix64);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS("[test.cpp:7]: (portability) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'size_t {aka unsigned long}'.\n", errout.str());
|
||||
|
||||
check("DWORD a;\n"
|
||||
"DWORD_PTR b;\n"
|
||||
"void foo() {\n"
|
||||
" printf(\"%u %u\", a, b);\n"
|
||||
"}\n", false, true, Settings::Win32A);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (portability) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'DWORD {aka unsigned long}'.\n"
|
||||
"[test.cpp:4]: (portability) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'DWORD_PTR {aka unsigned long}'.\n", errout.str());
|
||||
|
||||
check("unsigned long a[] = { 1, 2 };\n"
|
||||
"void foo() {\n"
|
||||
" printf(\"%d %d %x \", a[0], a[0], a[0]);\n"
|
||||
"}\n", false, false, Settings::Win32A);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned long'.\n"
|
||||
"[test.cpp:3]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned long'.\n"
|
||||
"[test.cpp:3]: (warning) %x in format string (no. 3) requires 'unsigned int' but the argument type is 'unsigned long'.\n", errout.str());
|
||||
|
||||
check("void foo (wchar_t c) {\n" // ticket #5051 false positive
|
||||
" printf(\"%c\", c);\n"
|
||||
"}\n", false, false, Settings::Win64);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win64);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
|
@ -3339,7 +3339,7 @@ private:
|
|||
|
||||
check("void f() {\n"
|
||||
" printf(\"%lu\", sizeof(char));\n"
|
||||
"}\n", false, true, Settings::Win64);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Win64);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (portability) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'size_t {aka unsigned long long}'.\n",
|
||||
errout.str());
|
||||
}
|
||||
|
@ -4127,7 +4127,7 @@ private:
|
|||
" printf(\"%I32d %I32u %I32x\", u32, u32, u32);\n"
|
||||
" printf(\"%I64d %I64u %I64x\", i64, i64, i64);\n"
|
||||
" printf(\"%I64d %I64u %I64x\", u64, u64, u64);\n"
|
||||
"}", false, true, Settings::Win32A);
|
||||
"}", false, true, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:8]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'size_t {aka unsigned long}'.\n"
|
||||
"[test.cpp:9]: (portability) %Iu in format string (no. 2) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long}'.\n"
|
||||
"[test.cpp:9]: (portability) %Ix in format string (no. 3) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long}'.\n"
|
||||
|
@ -4149,7 +4149,7 @@ private:
|
|||
" printf(\"%I32d %I32u %I32x\", u32, u32, u32);\n"
|
||||
" printf(\"%I64d %I64u %I64x\", i64, i64, i64);\n"
|
||||
" printf(\"%I64d %I64u %I64x\", u64, u64, u64);\n"
|
||||
"}", false, true, Settings::Win64);
|
||||
"}", false, true, cppcheck::Platform::Type::Win64);
|
||||
ASSERT_EQUALS("[test.cpp:8]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'size_t {aka unsigned long long}'.\n"
|
||||
"[test.cpp:9]: (portability) %Iu in format string (no. 2) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long long}'.\n"
|
||||
"[test.cpp:9]: (portability) %Ix in format string (no. 3) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long long}'.\n"
|
||||
|
@ -4194,23 +4194,23 @@ private:
|
|||
// ticket #5264
|
||||
check("void foo(LPARAM lp, WPARAM wp, LRESULT lr) {\n"
|
||||
" printf(\"%Ix %Ix %Ix\", lp, wp, lr);\n"
|
||||
"}\n", false, true, Settings::Win64);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Win64);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo(LPARAM lp, WPARAM wp, LRESULT lr) {\n"
|
||||
" printf(\"%Ix %Ix %Ix\", lp, wp, lr);\n"
|
||||
"}\n", false, true, Settings::Win32A);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo(UINT32 a, ::UINT32 b, Fred::UINT32 c) {\n"
|
||||
" printf(\"%d %d %d\", a, b, c);\n"
|
||||
"};\n", false, true, Settings::Win32A);
|
||||
"};\n", false, true, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (portability) %d in format string (no. 1) requires 'int' but the argument type is 'UINT32 {aka unsigned int}'.\n"
|
||||
"[test.cpp:2]: (portability) %d in format string (no. 2) requires 'int' but the argument type is 'UINT32 {aka unsigned int}'.\n", errout.str());
|
||||
|
||||
check("void foo(LPCVOID a, ::LPCVOID b, Fred::LPCVOID c) {\n"
|
||||
" printf(\"%d %d %d\", a, b, c);\n"
|
||||
"};\n", false, true, Settings::Win32A);
|
||||
"};\n", false, true, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'const void *'.\n"
|
||||
"[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const void *'.\n", errout.str());
|
||||
|
||||
|
@ -4220,7 +4220,7 @@ private:
|
|||
" printf(\"%zd\", s);\n"
|
||||
" printf(\"%zd%i\", s, i);\n"
|
||||
" printf(\"%zu\", s);\n"
|
||||
"}", false, true, Settings::Win32A);
|
||||
"}", false, true, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:6]: (portability) %zu in format string (no. 1) requires 'size_t' but the argument type is 'SSIZE_T {aka signed long}'.\n", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
|
@ -4229,7 +4229,7 @@ private:
|
|||
" printf(\"%zd\", s);\n"
|
||||
" printf(\"%zd%i\", s, i);\n"
|
||||
" printf(\"%zu\", s);\n"
|
||||
"}", false, true, Settings::Win64);
|
||||
"}", false, true, cppcheck::Platform::Type::Win64);
|
||||
ASSERT_EQUALS("[test.cpp:6]: (portability) %zu in format string (no. 1) requires 'size_t' but the argument type is 'SSIZE_T {aka signed long long}'.\n", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
|
@ -4238,7 +4238,7 @@ private:
|
|||
" printf(\"%zd\", s);\n"
|
||||
" printf(\"%zd%i\", s, i);\n"
|
||||
" printf(\"%zu\", s);\n"
|
||||
"}", false, true, Settings::Unix64);
|
||||
"}", false, true, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
|
@ -4248,7 +4248,7 @@ private:
|
|||
" printf(\"%zd\", s);\n"
|
||||
" printf(\"%zd%i\", s, i);\n"
|
||||
" printf(\"%zu\", s);\n"
|
||||
"}", false, true, Settings::Win64);
|
||||
"}", false, true, cppcheck::Platform::Type::Win64);
|
||||
ASSERT_EQUALS("[test.cpp:7]: (portability) %zu in format string (no. 1) requires 'size_t' but the argument type is 'SSIZE_T {aka signed long long}'.\n", errout.str());
|
||||
|
||||
}
|
||||
|
@ -4267,7 +4267,7 @@ private:
|
|||
" scanf(\"%I32d %I32u %I32x\", &u32, &u32, &u32);\n"
|
||||
" scanf(\"%I64d %I64u %I64x\", &i64, &i64, &i64);\n"
|
||||
" scanf(\"%I64d %I64u %I64x\", &u64, &u64, &u64);\n"
|
||||
"}", false, true, Settings::Win32A);
|
||||
"}", false, true, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:8]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t *' but the argument type is 'size_t * {aka unsigned long *}'.\n"
|
||||
"[test.cpp:9]: (portability) %Iu in format string (no. 2) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long *}'.\n"
|
||||
"[test.cpp:9]: (portability) %Ix in format string (no. 3) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long *}'.\n"
|
||||
|
@ -4291,7 +4291,7 @@ private:
|
|||
" scanf(\"%I32d %I32u %I32x\", &u32, &u32, &u32);\n"
|
||||
" scanf(\"%I64d %I64u %I64x\", &i64, &i64, &i64);\n"
|
||||
" scanf(\"%I64d %I64u %I64x\", &u64, &u64, &u64);\n"
|
||||
"}", false, true, Settings::Win64);
|
||||
"}", false, true, cppcheck::Platform::Type::Win64);
|
||||
ASSERT_EQUALS("[test.cpp:8]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t *' but the argument type is 'size_t * {aka unsigned long long *}'.\n"
|
||||
"[test.cpp:9]: (portability) %Iu in format string (no. 2) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long long *}'.\n"
|
||||
"[test.cpp:9]: (portability) %Ix in format string (no. 3) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long long *}'.\n"
|
||||
|
@ -4341,7 +4341,7 @@ private:
|
|||
" scanf(\"%zd\", &s);\n"
|
||||
" scanf(\"%zd%i\", &s, &i);\n"
|
||||
" scanf(\"%zu\", &s);\n"
|
||||
"}", false, true, Settings::Win32A);
|
||||
"}", false, true, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:6]: (portability) %zu in format string (no. 1) requires 'size_t *' but the argument type is 'SSIZE_T * {aka signed long *}'.\n", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
|
@ -4350,7 +4350,7 @@ private:
|
|||
" scanf(\"%zd\", &s);\n"
|
||||
" scanf(\"%zd%i\", &s, &i);\n"
|
||||
" scanf(\"%zu\", &s);\n"
|
||||
"}", false, true, Settings::Win64);
|
||||
"}", false, true, cppcheck::Platform::Type::Win64);
|
||||
ASSERT_EQUALS("[test.cpp:6]: (portability) %zu in format string (no. 1) requires 'size_t *' but the argument type is 'SSIZE_T * {aka signed long long *}'.\n", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
|
@ -4359,7 +4359,7 @@ private:
|
|||
" scanf(\"%zd\", &s);\n"
|
||||
" scanf(\"%zd%i\", &s, &i);\n"
|
||||
" scanf(\"%zu\", &s);\n"
|
||||
"}", false, true, Settings::Unix64);
|
||||
"}", false, true, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
|
@ -4369,7 +4369,7 @@ private:
|
|||
" scanf(\"%zd\", &s);\n"
|
||||
" scanf(\"%zd%i\", &s, &i);\n"
|
||||
" scanf(\"%zu\", &s);\n"
|
||||
"}", false, true, Settings::Win64);
|
||||
"}", false, true, cppcheck::Platform::Type::Win64);
|
||||
ASSERT_EQUALS("[test.cpp:7]: (portability) %zu in format string (no. 1) requires 'size_t *' but the argument type is 'SSIZE_T * {aka signed long long *}'.\n", errout.str());
|
||||
|
||||
}
|
||||
|
@ -4380,7 +4380,7 @@ private:
|
|||
" String string;\n"
|
||||
" string.Format(\"%I32d\", u32);\n"
|
||||
" string.AppendFormat(\"%I32d\", u32);\n"
|
||||
"}", false, true, Settings::Win32A);
|
||||
"}", false, true, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
|
@ -4388,7 +4388,7 @@ private:
|
|||
" CString string;\n"
|
||||
" string.Format(\"%I32d\", u32);\n"
|
||||
" string.AppendFormat(\"%I32d\", u32);\n"
|
||||
"}", false, true, Settings::Unix32);
|
||||
"}", false, true, cppcheck::Platform::Type::Unix32);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
|
@ -4397,7 +4397,7 @@ private:
|
|||
" string.Format(\"%I32d\", u32);\n"
|
||||
" string.AppendFormat(\"%I32d\", u32);\n"
|
||||
" CString::Format(\"%I32d\", u32);\n"
|
||||
"}", false, true, Settings::Win32A);
|
||||
"}", false, true, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'.\n"
|
||||
"[test.cpp:5]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'.\n"
|
||||
"[test.cpp:6]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'.\n", errout.str());
|
||||
|
@ -4408,7 +4408,7 @@ private:
|
|||
" int i;\n"
|
||||
" unsigned int u;\n"
|
||||
" _tprintf_s(_T(\"%d %u\"), u, i, 0);\n"
|
||||
"}\n", false, false, Settings::Win32A);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n"
|
||||
"[test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:4]: (warning) _tprintf_s format string requires 2 parameters but 3 are given.\n", errout.str());
|
||||
|
@ -4417,7 +4417,7 @@ private:
|
|||
" int i;\n"
|
||||
" unsigned int u;\n"
|
||||
" _tprintf_s(_T(\"%d %u\"), u, i, 0);\n"
|
||||
"}\n", false, false, Settings::Win32W);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n"
|
||||
"[test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:4]: (warning) _tprintf_s format string requires 2 parameters but 3 are given.\n", errout.str());
|
||||
|
@ -4426,7 +4426,7 @@ private:
|
|||
" int i;\n"
|
||||
" unsigned int u;\n"
|
||||
" printf_s(\"%d %u\", u, i, 0);\n"
|
||||
"}\n", false, false, Settings::Win32A);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n"
|
||||
"[test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:4]: (warning) printf_s format string requires 2 parameters but 3 are given.\n", errout.str());
|
||||
|
@ -4435,7 +4435,7 @@ private:
|
|||
" int i;\n"
|
||||
" unsigned int u;\n"
|
||||
" wprintf_s(L\"%d %u\", u, i, 0);\n"
|
||||
"}\n", false, false, Settings::Win32W);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n"
|
||||
"[test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:4]: (warning) wprintf_s format string requires 2 parameters but 3 are given.\n", errout.str());
|
||||
|
@ -4445,7 +4445,7 @@ private:
|
|||
" int i;\n"
|
||||
" unsigned int u;\n"
|
||||
" _stprintf_s(str, sizeof(str) / sizeof(TCHAR), _T(\"%d %u\"), u, i, 0);\n"
|
||||
"}\n", false, false, Settings::Win32A);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n"
|
||||
"[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:5]: (warning) _stprintf_s format string requires 2 parameters but 3 are given.\n", errout.str());
|
||||
|
@ -4455,7 +4455,7 @@ private:
|
|||
" int i;\n"
|
||||
" unsigned int u;\n"
|
||||
" _stprintf_s(str, sizeof(str) / sizeof(TCHAR), _T(\"%d %u\"), u, i, 0);\n"
|
||||
"}\n", false, false, Settings::Win32W);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n"
|
||||
"[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:5]: (warning) _stprintf_s format string requires 2 parameters but 3 are given.\n", errout.str());
|
||||
|
@ -4465,7 +4465,7 @@ private:
|
|||
" int i;\n"
|
||||
" unsigned int u;\n"
|
||||
" sprintf_s(str, sizeof(str), \"%d %u\", u, i, 0);\n"
|
||||
"}\n", false, false, Settings::Win32A);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n"
|
||||
"[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:5]: (warning) sprintf_s format string requires 2 parameters but 3 are given.\n", errout.str());
|
||||
|
@ -4475,7 +4475,7 @@ private:
|
|||
" int i;\n"
|
||||
" unsigned int u;\n"
|
||||
" sprintf_s(str, \"%d %u\", u, i, 0);\n"
|
||||
"}\n", false, false, Settings::Win32A);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n"
|
||||
"[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:5]: (warning) sprintf_s format string requires 2 parameters but 3 are given.\n", errout.str());
|
||||
|
@ -4485,7 +4485,7 @@ private:
|
|||
" int i;\n"
|
||||
" unsigned int u;\n"
|
||||
" swprintf_s(str, sizeof(str) / sizeof(wchar_t), L\"%d %u\", u, i, 0);\n"
|
||||
"}\n", false, false, Settings::Win32W);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n"
|
||||
"[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:5]: (warning) swprintf_s format string requires 2 parameters but 3 are given.\n", errout.str());
|
||||
|
@ -4495,7 +4495,7 @@ private:
|
|||
" int i;\n"
|
||||
" unsigned int u;\n"
|
||||
" swprintf_s(str, L\"%d %u\", u, i, 0);\n"
|
||||
"}\n", false, false, Settings::Win32W);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n"
|
||||
"[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:5]: (warning) swprintf_s format string requires 2 parameters but 3 are given.\n", errout.str());
|
||||
|
@ -4505,7 +4505,7 @@ private:
|
|||
" int i;\n"
|
||||
" unsigned int u;\n"
|
||||
" _sntprintf_s(str, sizeof(str) / sizeof(TCHAR), _TRUNCATE, _T(\"%d %u\"), u, i, 0);\n"
|
||||
"}\n", false, false, Settings::Win32A);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n"
|
||||
"[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:5]: (warning) _sntprintf_s format string requires 2 parameters but 3 are given.\n", errout.str());
|
||||
|
@ -4515,7 +4515,7 @@ private:
|
|||
" int i;\n"
|
||||
" unsigned int u;\n"
|
||||
" _sntprintf_s(str, sizeof(str) / sizeof(TCHAR), _TRUNCATE, _T(\"%d %u\"), u, i, 0);\n"
|
||||
"}\n", false, false, Settings::Win32W);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n"
|
||||
"[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:5]: (warning) _sntprintf_s format string requires 2 parameters but 3 are given.\n", errout.str());
|
||||
|
@ -4525,7 +4525,7 @@ private:
|
|||
" int i;\n"
|
||||
" unsigned int u;\n"
|
||||
" _snprintf_s(str, sizeof(str), _TRUNCATE, \"%d %u\", u, i, 0);\n"
|
||||
"}\n", false, false, Settings::Win32A);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n"
|
||||
"[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:5]: (warning) _snprintf_s format string requires 2 parameters but 3 are given.\n", errout.str());
|
||||
|
@ -4535,7 +4535,7 @@ private:
|
|||
" int i;\n"
|
||||
" unsigned int u;\n"
|
||||
" _snwprintf_s(str, sizeof(str) / sizeof(wchar_t), _TRUNCATE, L\"%d %u\", u, i, 0);\n"
|
||||
"}\n", false, false, Settings::Win32W);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n"
|
||||
"[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:5]: (warning) _snwprintf_s format string requires 2 parameters but 3 are given.\n", errout.str());
|
||||
|
@ -4544,7 +4544,7 @@ private:
|
|||
" int i;\n"
|
||||
" unsigned int u;\n"
|
||||
" _ftprintf_s(fp, _T(\"%d %u\"), u, i, 0);\n"
|
||||
"}\n", false, false, Settings::Win32A);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n"
|
||||
"[test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:4]: (warning) _ftprintf_s format string requires 2 parameters but 3 are given.\n", errout.str());
|
||||
|
@ -4553,7 +4553,7 @@ private:
|
|||
" int i;\n"
|
||||
" unsigned int u;\n"
|
||||
" _ftprintf_s(fp, _T(\"%d %u\"), u, i, 0);\n"
|
||||
"}\n", false, false, Settings::Win32W);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n"
|
||||
"[test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:4]: (warning) _ftprintf_s format string requires 2 parameters but 3 are given.\n", errout.str());
|
||||
|
@ -4562,7 +4562,7 @@ private:
|
|||
" int i;\n"
|
||||
" unsigned int u;\n"
|
||||
" fprintf_s(fp, \"%d %u\", u, i, 0);\n"
|
||||
"}\n", false, false, Settings::Win32A);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n"
|
||||
"[test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:4]: (warning) fprintf_s format string requires 2 parameters but 3 are given.\n", errout.str());
|
||||
|
@ -4571,7 +4571,7 @@ private:
|
|||
" int i;\n"
|
||||
" unsigned int u;\n"
|
||||
" fwprintf_s(fp, L\"%d %u\", u, i, 0);\n"
|
||||
"}\n", false, false, Settings::Win32W);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n"
|
||||
"[test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:4]: (warning) fwprintf_s format string requires 2 parameters but 3 are given.\n", errout.str());
|
||||
|
@ -4581,7 +4581,7 @@ private:
|
|||
" const char * const format = \"%15s%17s%17s%17s%17s\";\n"
|
||||
" sprintf_s(lineBuffer, 600, format, \"type\", \"sum\", \"avg\", \"min\", \"max\");\n"
|
||||
" sprintf_s(lineBuffer, format, \"type\", \"sum\", \"avg\", \"min\", \"max\");\n"
|
||||
"}\n", false, false, Settings::Win32A);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
|
@ -4601,7 +4601,7 @@ private:
|
|||
" sprintf_s(lineBuffer, 100, format1, \"type\", \"sum\", \"avg\", \"min\", i, 0);\n"
|
||||
" sprintf_s(lineBuffer, 100, format2, \"type\", \"sum\", \"avg\", \"min\", i, 0);\n"
|
||||
" sprintf_s(lineBuffer, 100, format3, \"type\", \"sum\", \"avg\", \"min\", i, 0);\n"
|
||||
"}\n", true, false, Settings::Win32A);
|
||||
"}\n", true, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:6]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'.\n"
|
||||
"[test.cpp:6]: (warning) sprintf_s format string requires 5 parameters but 6 are given.\n"
|
||||
"[test.cpp:7]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'.\n"
|
||||
|
@ -4635,7 +4635,7 @@ private:
|
|||
" unsigned int u;\n"
|
||||
" TCHAR str[10];\n"
|
||||
" _tscanf_s(_T(\"%s %d %u %[a-z]\"), str, 10, &u, &i, str, 10, 0)\n"
|
||||
"}\n", false, false, Settings::Win32A);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n"
|
||||
"[test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n"
|
||||
"[test.cpp:5]: (warning) _tscanf_s format string requires 6 parameters but 7 are given.\n", errout.str());
|
||||
|
@ -4645,7 +4645,7 @@ private:
|
|||
" unsigned int u;\n"
|
||||
" TCHAR str[10];\n"
|
||||
" _tscanf_s(_T(\"%s %d %u %[a-z]\"), str, 10, &u, &i, str, 10, 0)\n"
|
||||
"}\n", false, false, Settings::Win32W);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n"
|
||||
"[test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n"
|
||||
"[test.cpp:5]: (warning) _tscanf_s format string requires 6 parameters but 7 are given.\n", errout.str());
|
||||
|
@ -4655,7 +4655,7 @@ private:
|
|||
" unsigned int u;\n"
|
||||
" char str[10];\n"
|
||||
" scanf_s(\"%s %d %u %[a-z]\", str, 10, &u, &i, str, 10, 0)\n"
|
||||
"}\n", false, false, Settings::Win32A);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n"
|
||||
"[test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n"
|
||||
"[test.cpp:5]: (warning) scanf_s format string requires 6 parameters but 7 are given.\n", errout.str());
|
||||
|
@ -4665,7 +4665,7 @@ private:
|
|||
" unsigned int u;\n"
|
||||
" wchar_t str[10];\n"
|
||||
" wscanf_s(L\"%s %d %u %[a-z]\", str, 10, &u, &i, str, 10, 0)\n"
|
||||
"}\n", false, false, Settings::Win32W);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n"
|
||||
"[test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n"
|
||||
"[test.cpp:5]: (warning) wscanf_s format string requires 6 parameters but 7 are given.\n", errout.str());
|
||||
|
@ -4677,7 +4677,7 @@ private:
|
|||
"}\n",
|
||||
false,
|
||||
false,
|
||||
Settings::Win32A);
|
||||
cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Width 9 given in format string (no. 1) is larger than destination buffer 'str[8]', use %8c to prevent overflowing it.\n", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
|
@ -4686,7 +4686,7 @@ private:
|
|||
" unsigned int u;\n"
|
||||
" TCHAR str[10];\n"
|
||||
" _stscanf_s(txt, _T(\"%s %d %u %[a-z]\"), str, 10, &u, &i, str, 10, 0)\n"
|
||||
"}\n", false, false, Settings::Win32A);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:6]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n"
|
||||
"[test.cpp:6]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n"
|
||||
"[test.cpp:6]: (warning) _stscanf_s format string requires 6 parameters but 7 are given.\n", errout.str());
|
||||
|
@ -4697,7 +4697,7 @@ private:
|
|||
" unsigned int u;\n"
|
||||
" TCHAR str[10];\n"
|
||||
" _stscanf_s(txt, _T(\"%s %d %u %[a-z]\"), str, 10, &u, &i, str, 10, 0)\n"
|
||||
"}\n", false, false, Settings::Win32W);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:6]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n"
|
||||
"[test.cpp:6]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n"
|
||||
"[test.cpp:6]: (warning) _stscanf_s format string requires 6 parameters but 7 are given.\n", errout.str());
|
||||
|
@ -4708,7 +4708,7 @@ private:
|
|||
" unsigned int u;\n"
|
||||
" char str[10];\n"
|
||||
" sscanf_s(txt, \"%s %d %u %[a-z]\", str, 10, &u, &i, str, 10, 0)\n"
|
||||
"}\n", false, false, Settings::Win32A);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:6]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n"
|
||||
"[test.cpp:6]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n"
|
||||
"[test.cpp:6]: (warning) sscanf_s format string requires 6 parameters but 7 are given.\n", errout.str());
|
||||
|
@ -4719,7 +4719,7 @@ private:
|
|||
" unsigned int u;\n"
|
||||
" wchar_t str[10];\n"
|
||||
" swscanf_s(txt, L\"%s %d %u %[a-z]\", str, 10, &u, &i, str, 10, 0)\n"
|
||||
"}\n", false, false, Settings::Win32W);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:6]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n"
|
||||
"[test.cpp:6]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n"
|
||||
"[test.cpp:6]: (warning) swscanf_s format string requires 6 parameters but 7 are given.\n", errout.str());
|
||||
|
@ -4729,7 +4729,7 @@ private:
|
|||
" unsigned int u;\n"
|
||||
" TCHAR str[10];\n"
|
||||
" _ftscanf_s(fp, _T(\"%s %d %u %[a-z]\"), str, 10, &u, &i, str, 10, 0)\n"
|
||||
"}\n", false, false, Settings::Win32A);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n"
|
||||
"[test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n"
|
||||
"[test.cpp:5]: (warning) _ftscanf_s format string requires 6 parameters but 7 are given.\n", errout.str());
|
||||
|
@ -4739,7 +4739,7 @@ private:
|
|||
" unsigned int u;\n"
|
||||
" TCHAR str[10];\n"
|
||||
" _ftscanf_s(fp, _T(\"%s %d %u %[a-z]\"), str, 10, &u, &i, str, 10, 0)\n"
|
||||
"}\n", false, false, Settings::Win32W);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n"
|
||||
"[test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n"
|
||||
"[test.cpp:5]: (warning) _ftscanf_s format string requires 6 parameters but 7 are given.\n", errout.str());
|
||||
|
@ -4749,7 +4749,7 @@ private:
|
|||
" unsigned int u;\n"
|
||||
" char str[10];\n"
|
||||
" fscanf_s(fp, \"%s %d %u %[a-z]\", str, 10, &u, &i, str, 10, 0)\n"
|
||||
"}\n", false, false, Settings::Win32A);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n"
|
||||
"[test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n"
|
||||
"[test.cpp:5]: (warning) fscanf_s format string requires 6 parameters but 7 are given.\n", errout.str());
|
||||
|
@ -4759,7 +4759,7 @@ private:
|
|||
" unsigned int u;\n"
|
||||
" wchar_t str[10];\n"
|
||||
" fwscanf_s(fp, L\"%s %d %u %[a-z]\", str, 10, &u, &i, str, 10, 0)\n"
|
||||
"}\n", false, false, Settings::Win32W);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n"
|
||||
"[test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n"
|
||||
"[test.cpp:5]: (warning) fwscanf_s format string requires 6 parameters but 7 are given.\n", errout.str());
|
||||
|
@ -4767,7 +4767,7 @@ private:
|
|||
check("void foo() {\n"
|
||||
" WCHAR msStr1[5] = {0};\n"
|
||||
" wscanf_s(L\"%4[^-]\", msStr1, _countof(msStr1));\n"
|
||||
"}\n", false, false, Settings::Win32W);
|
||||
"}\n", false, false, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
@ -4775,13 +4775,13 @@ private:
|
|||
check("void foo(float f) {\n"
|
||||
" QString string;\n"
|
||||
" string.sprintf(\"%d\", f);\n"
|
||||
"}", false, false, Settings::Win32A);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'float'.\n", errout.str());
|
||||
|
||||
check("void foo(float f) {\n"
|
||||
" QString string;\n"
|
||||
" string = QString::asprintf(\"%d\", f);\n"
|
||||
"}", false, false, Settings::Win32A);
|
||||
"}", false, false, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'float'.\n", errout.str());
|
||||
}
|
||||
|
||||
|
@ -4841,7 +4841,7 @@ private:
|
|||
// 8141
|
||||
check("void f(int i) {\n"
|
||||
" printf(\"%f\", imaxabs(i));\n"
|
||||
"}\n", false, true, Settings::Unix64);
|
||||
"}\n", false, true, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (portability) %f in format string (no. 1) requires 'double' but the argument type is 'intmax_t {aka signed long}'.\n", errout.str());
|
||||
}
|
||||
|
||||
|
|
|
@ -362,7 +362,7 @@ private:
|
|||
|
||||
void checkInterlockedDecrement(const char code[]) {
|
||||
Settings settings;
|
||||
settings.platformType = Settings::Win32A;
|
||||
settings.platform.type = cppcheck::Platform::Type::Win32A;
|
||||
|
||||
check(code, nullptr, false, false, true, false, &settings);
|
||||
}
|
||||
|
@ -1753,7 +1753,7 @@ private:
|
|||
if (portability)
|
||||
settings.severity.enable(Severity::portability);
|
||||
settings.certainty.setEnabled(Certainty::inconclusive, inconclusive);
|
||||
settings.defaultSign = 's';
|
||||
settings.platform.defaultSign = 's';
|
||||
|
||||
Preprocessor preprocessor(settings, nullptr);
|
||||
|
||||
|
@ -1997,7 +1997,7 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
Settings settings1;
|
||||
PLATFORM(settings1, cppcheck::Platform::Win64);
|
||||
PLATFORM(settings1.platform, cppcheck::Platform::Type::Win64);
|
||||
check("using ui64 = unsigned __int64;\n"
|
||||
"ui64 Test(ui64 one, ui64 two) { return one + two; }\n",
|
||||
/*filename*/ nullptr, /*experimental*/ false, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);
|
||||
|
@ -2143,12 +2143,12 @@ private:
|
|||
"void f(X x) {}";
|
||||
|
||||
Settings s32(_settings);
|
||||
PLATFORM(s32, cppcheck::Platform::Unix32);
|
||||
PLATFORM(s32.platform, cppcheck::Platform::Type::Unix32);
|
||||
check(code, &s32);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (performance) Function parameter 'x' should be passed by const reference.\n", errout.str());
|
||||
|
||||
Settings s64(_settings);
|
||||
PLATFORM(s64, cppcheck::Platform::Unix64);
|
||||
PLATFORM(s64.platform, cppcheck::Platform::Type::Unix64);
|
||||
check(code, &s64);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
@ -6483,16 +6483,16 @@ private:
|
|||
" bar( (flag) ? ~0u : ~0ul);\n"
|
||||
"}";
|
||||
Settings settings = _settings;
|
||||
settings.sizeof_int = 4;
|
||||
settings.int_bit = 32;
|
||||
settings.platform.sizeof_int = 4;
|
||||
settings.platform.int_bit = 32;
|
||||
|
||||
settings.sizeof_long = 4;
|
||||
settings.long_bit = 32;
|
||||
settings.platform.sizeof_long = 4;
|
||||
settings.platform.long_bit = 32;
|
||||
check(code, &settings);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Same value in both branches of ternary operator.\n", errout.str());
|
||||
|
||||
settings.sizeof_long = 8;
|
||||
settings.long_bit = 64;
|
||||
settings.platform.sizeof_long = 8;
|
||||
settings.platform.long_bit = 64;
|
||||
check(code, &settings);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
@ -7425,7 +7425,7 @@ private:
|
|||
|
||||
// #9040
|
||||
Settings settings1;
|
||||
PLATFORM(settings1, cppcheck::Platform::Win64);
|
||||
PLATFORM(settings1.platform, cppcheck::Platform::Type::Win64);
|
||||
check("using BOOL = unsigned;\n"
|
||||
"int i;\n"
|
||||
"bool f() {\n"
|
||||
|
|
|
@ -59,9 +59,9 @@ private:
|
|||
void valid_config_win32a() const {
|
||||
// Verify if native Win32A platform is loaded correctly
|
||||
cppcheck::Platform platform;
|
||||
PLATFORM(platform, cppcheck::Platform::Win32A);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Win32A, platform.platformType);
|
||||
ASSERT(platform.isWindowsPlatform());
|
||||
PLATFORM(platform, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Win32A, platform.type);
|
||||
ASSERT(platform.isWindows());
|
||||
ASSERT_EQUALS(1, platform.sizeof_bool);
|
||||
ASSERT_EQUALS(2, platform.sizeof_short);
|
||||
ASSERT_EQUALS(4, platform.sizeof_int);
|
||||
|
@ -84,9 +84,9 @@ private:
|
|||
void valid_config_unix64() const {
|
||||
// Verify if native Unix64 platform is loaded correctly
|
||||
cppcheck::Platform platform;
|
||||
PLATFORM(platform, cppcheck::Platform::Unix64);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Unix64, platform.platformType);
|
||||
ASSERT(!platform.isWindowsPlatform());
|
||||
PLATFORM(platform, cppcheck::Platform::Type::Unix64);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Unix64, platform.type);
|
||||
ASSERT(!platform.isWindows());
|
||||
ASSERT_EQUALS(1, platform.sizeof_bool);
|
||||
ASSERT_EQUALS(2, platform.sizeof_short);
|
||||
ASSERT_EQUALS(4, platform.sizeof_int);
|
||||
|
@ -109,9 +109,9 @@ private:
|
|||
void valid_config_win32w() const {
|
||||
// Verify if native Win32W platform is loaded correctly
|
||||
cppcheck::Platform platform;
|
||||
PLATFORM(platform, cppcheck::Platform::Win32W);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Win32W, platform.platformType);
|
||||
ASSERT(platform.isWindowsPlatform());
|
||||
PLATFORM(platform, cppcheck::Platform::Type::Win32W);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Win32W, platform.type);
|
||||
ASSERT(platform.isWindows());
|
||||
ASSERT_EQUALS(1, platform.sizeof_bool);
|
||||
ASSERT_EQUALS(2, platform.sizeof_short);
|
||||
ASSERT_EQUALS(4, platform.sizeof_int);
|
||||
|
@ -134,9 +134,9 @@ private:
|
|||
void valid_config_unix32() const {
|
||||
// Verify if native Unix32 platform is loaded correctly
|
||||
cppcheck::Platform platform;
|
||||
PLATFORM(platform, cppcheck::Platform::Unix32);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Unix32, platform.platformType);
|
||||
ASSERT(!platform.isWindowsPlatform());
|
||||
PLATFORM(platform, cppcheck::Platform::Type::Unix32);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Unix32, platform.type);
|
||||
ASSERT(!platform.isWindows());
|
||||
ASSERT_EQUALS(1, platform.sizeof_bool);
|
||||
ASSERT_EQUALS(2, platform.sizeof_short);
|
||||
ASSERT_EQUALS(4, platform.sizeof_int);
|
||||
|
@ -159,9 +159,9 @@ private:
|
|||
void valid_config_win64() const {
|
||||
// Verify if native Win64 platform is loaded correctly
|
||||
cppcheck::Platform platform;
|
||||
PLATFORM(platform, cppcheck::Platform::Win64);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Win64, platform.platformType);
|
||||
ASSERT(platform.isWindowsPlatform());
|
||||
PLATFORM(platform, cppcheck::Platform::Type::Win64);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Win64, platform.type);
|
||||
ASSERT(platform.isWindows());
|
||||
ASSERT_EQUALS(1, platform.sizeof_bool);
|
||||
ASSERT_EQUALS(2, platform.sizeof_short);
|
||||
ASSERT_EQUALS(4, platform.sizeof_int);
|
||||
|
@ -204,8 +204,8 @@ private:
|
|||
" </platform>";
|
||||
cppcheck::Platform platform;
|
||||
ASSERT(readPlatform(platform, xmldata));
|
||||
ASSERT_EQUALS(platform.PlatformFile, platform.platformType);
|
||||
ASSERT(!platform.isWindowsPlatform());
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::File, platform.type);
|
||||
ASSERT(!platform.isWindows());
|
||||
ASSERT_EQUALS(8, platform.char_bit);
|
||||
ASSERT_EQUALS('u', platform.defaultSign);
|
||||
ASSERT_EQUALS(1, platform.sizeof_bool);
|
||||
|
@ -248,8 +248,8 @@ private:
|
|||
" </platform>";
|
||||
cppcheck::Platform platform;
|
||||
ASSERT(readPlatform(platform, xmldata));
|
||||
ASSERT_EQUALS(platform.PlatformFile, platform.platformType);
|
||||
ASSERT(!platform.isWindowsPlatform());
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::File, platform.type);
|
||||
ASSERT(!platform.isWindows());
|
||||
ASSERT_EQUALS(20, platform.char_bit);
|
||||
ASSERT_EQUALS('s', platform.defaultSign);
|
||||
ASSERT_EQUALS(1, platform.sizeof_bool);
|
||||
|
@ -318,8 +318,8 @@ private:
|
|||
" </platform>";
|
||||
cppcheck::Platform platform;
|
||||
ASSERT(readPlatform(platform, xmldata));
|
||||
ASSERT_EQUALS(platform.PlatformFile, platform.platformType);
|
||||
ASSERT(!platform.isWindowsPlatform());
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::File, platform.type);
|
||||
ASSERT(!platform.isWindows());
|
||||
ASSERT_EQUALS(0, platform.char_bit);
|
||||
ASSERT_EQUALS('z', platform.defaultSign);
|
||||
ASSERT_EQUALS(0, platform.sizeof_bool);
|
||||
|
@ -391,11 +391,11 @@ private:
|
|||
void default_platform() {
|
||||
cppcheck::Platform platform;
|
||||
#if defined(_WIN64)
|
||||
ASSERT_EQUALS(cppcheck::Platform::Win64, platform.platformType);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Win64, platform.type);
|
||||
#elif defined(_WIN32)
|
||||
ASSERT_EQUALS(cppcheck::Platform::Win32A, platform.platformType);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Win32A, platform.type);
|
||||
#else
|
||||
ASSERT_EQUALS(cppcheck::Platform::Native, platform.platformType);
|
||||
ASSERT_EQUALS(cppcheck::Platform::Type::Native, platform.type);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
|
|
@ -478,12 +478,12 @@ private:
|
|||
simplecpp::TokenList tokens(istr, files, "test.c");
|
||||
|
||||
// preprocess code with unix32 platform..
|
||||
PLATFORM(settings, Settings::PlatformType::Unix32);
|
||||
PLATFORM(settings.platform, cppcheck::Platform::Type::Unix32);
|
||||
preprocessor.setPlatformInfo(&tokens);
|
||||
ASSERT_EQUALS("\n1", preprocessor.getcode(tokens, "", files, false));
|
||||
|
||||
// preprocess code with unix64 platform..
|
||||
PLATFORM(settings, Settings::PlatformType::Unix64);
|
||||
PLATFORM(settings.platform, cppcheck::Platform::Type::Unix64);
|
||||
preprocessor.setPlatformInfo(&tokens);
|
||||
ASSERT_EQUALS("\n\n\n2", preprocessor.getcode(tokens, "", files, false));
|
||||
}
|
||||
|
|
|
@ -309,11 +309,11 @@ private:
|
|||
}
|
||||
|
||||
#define tok(...) tok_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
std::string tok_(const char* file, int line, const char code[], bool debugwarnings = false, Settings::PlatformType type = Settings::Native) {
|
||||
std::string tok_(const char* file, int line, const char code[], bool debugwarnings = false, cppcheck::Platform::Type type = cppcheck::Platform::Type::Native) {
|
||||
errout.str("");
|
||||
|
||||
settings.debugwarnings = debugwarnings;
|
||||
PLATFORM(settings, type);
|
||||
PLATFORM(settings.platform, type);
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
|
||||
std::istringstream istr(code);
|
||||
|
|
|
@ -175,10 +175,10 @@ private:
|
|||
}
|
||||
|
||||
#define tok(...) tok_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
std::string tok_(const char* file, int line, const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native) {
|
||||
std::string tok_(const char* file, int line, const char code[], bool simplify = true, cppcheck::Platform::Type type = cppcheck::Platform::Type::Native) {
|
||||
errout.str("");
|
||||
|
||||
PLATFORM(settings0, type);
|
||||
PLATFORM(settings0.platform, type);
|
||||
Tokenizer tokenizer(&settings0, this);
|
||||
|
||||
std::istringstream istr(code);
|
||||
|
@ -203,11 +203,11 @@ private:
|
|||
}
|
||||
|
||||
#define tokenizeAndStringify(...) tokenizeAndStringify_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
std::string tokenizeAndStringify_(const char* file, int linenr, const char code[], bool simplify = false, bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) {
|
||||
std::string tokenizeAndStringify_(const char* file, int linenr, const char code[], bool simplify = false, bool expand = true, cppcheck::Platform::Type platform = cppcheck::Platform::Type::Native, const char* filename = "test.cpp", bool cpp11 = true) {
|
||||
errout.str("");
|
||||
|
||||
settings1.debugwarnings = true;
|
||||
PLATFORM(settings1, platform);
|
||||
PLATFORM(settings1.platform, platform);
|
||||
settings1.standards.cpp = cpp11 ? Standards::CPP11 : Standards::CPP03;
|
||||
|
||||
// tokenize..
|
||||
|
@ -269,10 +269,10 @@ private:
|
|||
ASSERT_EQUALS(tok(code2), tok(code1));
|
||||
|
||||
const char code3[] = "x = L\"1\" TEXT(\"2\") L\"3\";";
|
||||
ASSERT_EQUALS("x = L\"123\" ;", tok(code3, false, Settings::Win64));
|
||||
ASSERT_EQUALS("x = L\"123\" ;", tok(code3, false, cppcheck::Platform::Type::Win64));
|
||||
|
||||
const char code4[] = "x = TEXT(\"1\") L\"2\";";
|
||||
ASSERT_EQUALS("x = L\"1\" L\"2\" ;", tok(code4, false, Settings::Win64));
|
||||
ASSERT_EQUALS("x = L\"1\" L\"2\" ;", tok(code4, false, cppcheck::Platform::Type::Win64));
|
||||
}
|
||||
|
||||
void combine_wstrings() {
|
||||
|
@ -1324,12 +1324,12 @@ private:
|
|||
ASSERT_EQUALS("int f ( ) ;", tok("int __far __syscall f();"));
|
||||
ASSERT_EQUALS("int f ( ) ;", tok("int __far __pascal f();"));
|
||||
ASSERT_EQUALS("int f ( ) ;", tok("int __far __fortran f();"));
|
||||
ASSERT_EQUALS("int f ( ) ;", tok("int WINAPI f();", true, Settings::Win32A));
|
||||
ASSERT_EQUALS("int f ( ) ;", tok("int APIENTRY f();", true, Settings::Win32A));
|
||||
ASSERT_EQUALS("int f ( ) ;", tok("int CALLBACK f();", true, Settings::Win32A));
|
||||
ASSERT_EQUALS("int f ( ) ;", tok("int WINAPI f();", true, cppcheck::Platform::Type::Win32A));
|
||||
ASSERT_EQUALS("int f ( ) ;", tok("int APIENTRY f();", true, cppcheck::Platform::Type::Win32A));
|
||||
ASSERT_EQUALS("int f ( ) ;", tok("int CALLBACK f();", true, cppcheck::Platform::Type::Win32A));
|
||||
|
||||
// don't simplify Microsoft defines in unix code (#7554)
|
||||
ASSERT_EQUALS("enum E { CALLBACK } ;", tok("enum E { CALLBACK } ;", true, Settings::Unix32));
|
||||
ASSERT_EQUALS("enum E { CALLBACK } ;", tok("enum E { CALLBACK } ;", true, cppcheck::Platform::Type::Unix32));
|
||||
}
|
||||
|
||||
void simplifyAttribute() {
|
||||
|
@ -2054,7 +2054,7 @@ private:
|
|||
"strcpy ( a , \"hello\" ) ;\n"
|
||||
"strcat ( a , \"!\" ) ;\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -2150,7 +2150,7 @@ private:
|
|||
"cin >> x ;\n"
|
||||
"return x ;\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Native, "test.cpp"));
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, cppcheck::Platform::Type::Native, "test.cpp"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2164,7 +2164,7 @@ private:
|
|||
"int x ; x = 0 ;\n"
|
||||
"cin >> std :: hex >> x ;\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Native, "test.cpp"));
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, cppcheck::Platform::Type::Native, "test.cpp"));
|
||||
}
|
||||
|
||||
void simplifyKnownVariables48() {
|
||||
|
@ -2177,7 +2177,7 @@ private:
|
|||
"int i ;\n"
|
||||
"for ( i = 0 ; ( i < sz ) && ( sz > 3 ) ; ++ i ) { }\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
}
|
||||
|
||||
void simplifyKnownVariables49() { // #3691
|
||||
|
@ -2193,7 +2193,7 @@ private:
|
|||
"case 2 : ; x = sz ; break ;\n"
|
||||
"}\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
}
|
||||
|
||||
void simplifyKnownVariables50() { // #4066
|
||||
|
|
|
@ -209,12 +209,12 @@ private:
|
|||
}
|
||||
|
||||
#define tok(...) tok_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
std::string tok_(const char* file, int line, const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) {
|
||||
std::string tok_(const char* file, int line, const char code[], bool simplify = true, cppcheck::Platform::Type type = cppcheck::Platform::Type::Native, bool debugwarnings = true) {
|
||||
errout.str("");
|
||||
|
||||
settings0.certainty.enable(Certainty::inconclusive);
|
||||
settings0.debugwarnings = debugwarnings; // show warnings about unhandled typedef
|
||||
PLATFORM(settings0, type);
|
||||
PLATFORM(settings0.platform, type);
|
||||
Tokenizer tokenizer(&settings0, this);
|
||||
|
||||
std::istringstream istr(code);
|
||||
|
@ -563,7 +563,7 @@ private:
|
|||
"};";
|
||||
|
||||
// Tokenize and check output..
|
||||
TODO_ASSERT_THROW(tok(code, true, Settings::Native, false), InternalError); // TODO: Do not throw exception
|
||||
TODO_ASSERT_THROW(tok(code, true, cppcheck::Platform::Type::Native, false), InternalError); // TODO: Do not throw exception
|
||||
//ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
@ -1647,7 +1647,7 @@ private:
|
|||
|
||||
// The expected tokens..
|
||||
const char expected2[] = "void f ( ) { char a [ 256 ] ; a = { 0 } ; char b [ 256 ] ; b = { 0 } ; }";
|
||||
ASSERT_EQUALS(expected2, tok(code2, false, Settings::Native, false));
|
||||
ASSERT_EQUALS(expected2, tok(code2, false, cppcheck::Platform::Type::Native, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
const char code3[] = "typedef char TString[256];\n"
|
||||
|
@ -1658,7 +1658,7 @@ private:
|
|||
|
||||
// The expected tokens..
|
||||
const char expected3[] = "void f ( ) { char a [ 256 ] ; a = \"\" ; char b [ 256 ] ; b = \"\" ; }";
|
||||
ASSERT_EQUALS(expected3, tok(code3, false, Settings::Native, false));
|
||||
ASSERT_EQUALS(expected3, tok(code3, false, cppcheck::Platform::Type::Native, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
const char code4[] = "typedef char TString[256];\n"
|
||||
|
@ -1669,7 +1669,7 @@ private:
|
|||
|
||||
// The expected tokens..
|
||||
const char expected4[] = "void f ( ) { char a [ 256 ] ; a = \"1234\" ; char b [ 256 ] ; b = \"5678\" ; }";
|
||||
ASSERT_EQUALS(expected4, tok(code4, false, Settings::Native, false));
|
||||
ASSERT_EQUALS(expected4, tok(code4, false, cppcheck::Platform::Type::Native, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
@ -1695,7 +1695,7 @@ private:
|
|||
" Foo b(0);\n"
|
||||
" return b > Foo(10);\n"
|
||||
"}";
|
||||
const std::string actual(tok(code, true, Settings::Native, false));
|
||||
const std::string actual(tok(code, true, cppcheck::Platform::Type::Native, false));
|
||||
ASSERT_EQUALS("int main ( ) { BAR < int > b ( 0 ) ; return b > BAR < int > ( 10 ) ; }", actual);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
@ -1851,14 +1851,14 @@ private:
|
|||
|
||||
void simplifyTypedef75() { // ticket #2426
|
||||
const char code[] = "typedef _Packed struct S { long l; };";
|
||||
ASSERT_EQUALS(";", tok(code, true, Settings::Native, false));
|
||||
ASSERT_EQUALS(";", tok(code, true, cppcheck::Platform::Type::Native, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void simplifyTypedef76() { // ticket #2453 segmentation fault
|
||||
const char code[] = "void f1(typedef int x) {}";
|
||||
const char expected[] = "void f1 ( typedef int x ) { }";
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Native, false));
|
||||
ASSERT_EQUALS(expected, tok(code, true, cppcheck::Platform::Type::Native, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
@ -2176,7 +2176,7 @@ private:
|
|||
"public: "
|
||||
"expression_error :: error_code ( * f ) ( void * , const char * , expression_space ) ; "
|
||||
"} ;";
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Native, false));
|
||||
ASSERT_EQUALS(expected, tok(code, true, cppcheck::Platform::Type::Native, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
@ -2340,7 +2340,7 @@ private:
|
|||
"} ; "
|
||||
"} "
|
||||
"}";
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Native, false));
|
||||
ASSERT_EQUALS(expected, tok(code, true, cppcheck::Platform::Type::Native, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
@ -2818,7 +2818,7 @@ private:
|
|||
"void A :: f ( external :: ns1 :: B<1> ) { } "
|
||||
"} "
|
||||
"struct external :: ns1 :: B<1> { } ;";
|
||||
ASSERT_EQUALS(exp, tok(code, true, Settings::Native, true));
|
||||
ASSERT_EQUALS(exp, tok(code, true, cppcheck::Platform::Type::Native, true));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
{
|
||||
|
@ -2851,7 +2851,7 @@ private:
|
|||
"void A :: f ( external :: ns1 :: B<1> ) { } "
|
||||
"} "
|
||||
"struct external :: ns1 :: B<1> { } ;";
|
||||
ASSERT_EQUALS(exp, tok(code, true, Settings::Native, true));
|
||||
ASSERT_EQUALS(exp, tok(code, true, cppcheck::Platform::Type::Native, true));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
{
|
||||
|
@ -2901,7 +2901,7 @@ private:
|
|||
"void A :: f ( V ) { } "
|
||||
"} "
|
||||
"struct external :: ns1 :: B<1> { } ;";
|
||||
TODO_ASSERT_EQUALS(exp, act, tok(code, true, Settings::Native, true));
|
||||
TODO_ASSERT_EQUALS(exp, act, tok(code, true, cppcheck::Platform::Type::Native, true));
|
||||
TODO_ASSERT_EQUALS("", "[test.cpp:14]: (debug) Executable scope 'f' with unknown function.\n", errout.str());
|
||||
}
|
||||
{
|
||||
|
@ -2950,7 +2950,7 @@ private:
|
|||
"namespace ns { "
|
||||
"void A :: f ( V ) { } "
|
||||
"}";
|
||||
TODO_ASSERT_EQUALS(exp, act, tok(code, true, Settings::Native, true));
|
||||
TODO_ASSERT_EQUALS(exp, act, tok(code, true, cppcheck::Platform::Type::Native, true));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
{
|
||||
|
@ -2980,7 +2980,7 @@ private:
|
|||
"void A :: f ( external :: B<1> ) { } "
|
||||
"} "
|
||||
"struct external :: B<1> { } ;";
|
||||
ASSERT_EQUALS(exp, tok(code, true, Settings::Native, true));
|
||||
ASSERT_EQUALS(exp, tok(code, true, cppcheck::Platform::Type::Native, true));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
{
|
||||
|
@ -3008,7 +3008,7 @@ private:
|
|||
"void A :: f ( B<1> ) { } "
|
||||
"} "
|
||||
"struct B<1> { } ;";
|
||||
ASSERT_EQUALS(exp, tok(code, true, Settings::Native, true));
|
||||
ASSERT_EQUALS(exp, tok(code, true, cppcheck::Platform::Type::Native, true));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
}
|
||||
|
@ -3328,7 +3328,7 @@ private:
|
|||
"C ( * f5 ) ( ) ; "
|
||||
"C ( * f6 ) ( ) ; "
|
||||
"C ( * f7 ) ( ) ;";
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Native, false));
|
||||
ASSERT_EQUALS(expected, tok(code, true, cppcheck::Platform::Type::Native, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
@ -3357,7 +3357,7 @@ private:
|
|||
"const C ( * f5 ) ( ) ; "
|
||||
"const C ( * f6 ) ( ) ; "
|
||||
"const C ( * f7 ) ( ) ;";
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Native, false));
|
||||
ASSERT_EQUALS(expected, tok(code, true, cppcheck::Platform::Type::Native, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
@ -3385,7 +3385,7 @@ private:
|
|||
"const C ( * f5 ) ( ) ; "
|
||||
"const C ( * f6 ) ( ) ; "
|
||||
"const C ( * f7 ) ( ) ;";
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Native, false));
|
||||
ASSERT_EQUALS(expected, tok(code, true, cppcheck::Platform::Type::Native, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
@ -3413,7 +3413,7 @@ private:
|
|||
"C * ( * f5 ) ( ) ; "
|
||||
"C * ( * f6 ) ( ) ; "
|
||||
"C * ( * f7 ) ( ) ;";
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Native, false));
|
||||
ASSERT_EQUALS(expected, tok(code, true, cppcheck::Platform::Type::Native, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
@ -3441,7 +3441,7 @@ private:
|
|||
"const C * ( * f5 ) ( ) ; "
|
||||
"const C * ( * f6 ) ( ) ; "
|
||||
"const C * ( * f7 ) ( ) ;";
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Native, false));
|
||||
ASSERT_EQUALS(expected, tok(code, true, cppcheck::Platform::Type::Native, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
@ -3470,7 +3470,7 @@ private:
|
|||
"const C * ( * f5 ) ( ) ; "
|
||||
"const C * ( * f6 ) ( ) ; "
|
||||
"const C * ( * f7 ) ( ) ;";
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Native, false));
|
||||
ASSERT_EQUALS(expected, tok(code, true, cppcheck::Platform::Type::Native, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
}
|
||||
|
@ -3615,7 +3615,7 @@ private:
|
|||
"B :: C ( * f2 ) ( ) ; "
|
||||
"B :: C ( * f3 ) ( ) ; "
|
||||
"B :: C ( * f4 ) ( ) ;";
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Native, false));
|
||||
ASSERT_EQUALS(expected, tok(code, true, cppcheck::Platform::Type::Native, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
@ -3653,7 +3653,7 @@ private:
|
|||
"A :: B :: C ( * f2 ) ( ) ; "
|
||||
"A :: B :: C ( * f3 ) ( ) ; "
|
||||
"A :: B :: C ( * f4 ) ( ) ;";
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Native, false));
|
||||
ASSERT_EQUALS(expected, tok(code, true, cppcheck::Platform::Type::Native, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,12 +98,12 @@ private:
|
|||
}
|
||||
|
||||
#define tok(...) tok_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
std::string tok_(const char* file, int line, const char code[], Settings::PlatformType type = Settings::Native, bool debugwarnings = true) {
|
||||
std::string tok_(const char* file, int line, const char code[], cppcheck::Platform::Type type = cppcheck::Platform::Type::Native, bool debugwarnings = true) {
|
||||
errout.str("");
|
||||
|
||||
settings0.certainty.enable(Certainty::inconclusive);
|
||||
settings0.debugwarnings = debugwarnings;
|
||||
PLATFORM(settings0, type);
|
||||
PLATFORM(settings0.platform, type);
|
||||
Tokenizer tokenizer(&settings0, this);
|
||||
|
||||
std::istringstream istr(code);
|
||||
|
@ -406,7 +406,7 @@ private:
|
|||
" FP_M(val);"
|
||||
"};";
|
||||
|
||||
TODO_ASSERT_THROW(tok(code, Settings::Native, false), InternalError); // TODO: Do not throw AST validation exception
|
||||
TODO_ASSERT_THROW(tok(code, cppcheck::Platform::Type::Native, false), InternalError); // TODO: Do not throw AST validation exception
|
||||
//ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
@ -696,11 +696,11 @@ private:
|
|||
|
||||
const char exp[] = "int i ;";
|
||||
|
||||
ASSERT_EQUALS(exp, tok(code, Settings::Unix32));
|
||||
ASSERT_EQUALS(exp, tok(code, Settings::Unix64));
|
||||
ASSERT_EQUALS(exp, tok(code, Settings::Win32A));
|
||||
ASSERT_EQUALS(exp, tok(code, Settings::Win32W));
|
||||
ASSERT_EQUALS(exp, tok(code, Settings::Win64));
|
||||
ASSERT_EQUALS(exp, tok(code, cppcheck::Platform::Type::Unix32));
|
||||
ASSERT_EQUALS(exp, tok(code, cppcheck::Platform::Type::Unix64));
|
||||
ASSERT_EQUALS(exp, tok(code, cppcheck::Platform::Type::Win32A));
|
||||
ASSERT_EQUALS(exp, tok(code, cppcheck::Platform::Type::Win32W));
|
||||
ASSERT_EQUALS(exp, tok(code, cppcheck::Platform::Type::Win64));
|
||||
}
|
||||
|
||||
void simplifyUsing9042() {
|
||||
|
@ -720,7 +720,7 @@ private:
|
|||
"} ; "
|
||||
"template < class T > class s { } ;";
|
||||
|
||||
ASSERT_EQUALS(exp, tok(code, Settings::Win64));
|
||||
ASSERT_EQUALS(exp, tok(code, cppcheck::Platform::Type::Win64));
|
||||
}
|
||||
|
||||
void simplifyUsing9191() {
|
||||
|
|
|
@ -120,7 +120,7 @@ private:
|
|||
|
||||
void run() override {
|
||||
LOAD_LIB_2(settings1.library, "std.cfg");
|
||||
PLATFORM(settings2, cppcheck::Platform::Unspecified);
|
||||
PLATFORM(settings2.platform, cppcheck::Platform::Type::Unspecified);
|
||||
|
||||
// If there are unused templates, keep those
|
||||
settings1.checkUnusedTemplates = true;
|
||||
|
@ -5473,18 +5473,18 @@ private:
|
|||
ASSERT(db->variableList().size() == 13); // the first one is not used
|
||||
const Variable * v;
|
||||
unsigned int id = 1;
|
||||
TEST(settings1.sizeof_int);
|
||||
TEST(settings1.sizeof_int);
|
||||
TEST(settings1.platform.sizeof_int);
|
||||
TEST(settings1.platform.sizeof_int);
|
||||
TEST(1);
|
||||
TEST(1);
|
||||
TEST(settings1.sizeof_short);
|
||||
TEST(settings1.sizeof_short);
|
||||
TEST(settings1.sizeof_int);
|
||||
TEST(settings1.sizeof_int);
|
||||
TEST(settings1.sizeof_long);
|
||||
TEST(settings1.sizeof_long);
|
||||
TEST(settings1.sizeof_long_long);
|
||||
TEST(settings1.sizeof_long_long);
|
||||
TEST(settings1.platform.sizeof_short);
|
||||
TEST(settings1.platform.sizeof_short);
|
||||
TEST(settings1.platform.sizeof_int);
|
||||
TEST(settings1.platform.sizeof_int);
|
||||
TEST(settings1.platform.sizeof_long);
|
||||
TEST(settings1.platform.sizeof_long);
|
||||
TEST(settings1.platform.sizeof_long_long);
|
||||
TEST(settings1.platform.sizeof_long_long);
|
||||
}
|
||||
|
||||
void enum8() {
|
||||
|
@ -7617,14 +7617,14 @@ private:
|
|||
ASSERT_EQUALS("", ValueType().str());
|
||||
|
||||
Settings s;
|
||||
s.int_bit = 16;
|
||||
s.long_bit = 32;
|
||||
s.long_long_bit = 64;
|
||||
s.platform.int_bit = 16;
|
||||
s.platform.long_bit = 32;
|
||||
s.platform.long_long_bit = 64;
|
||||
|
||||
Settings sSameSize;
|
||||
sSameSize.int_bit = 32;
|
||||
sSameSize.long_bit = 64;
|
||||
sSameSize.long_long_bit = 64;
|
||||
sSameSize.platform.int_bit = 32;
|
||||
sSameSize.platform.long_bit = 64;
|
||||
sSameSize.platform.long_long_bit = 64;
|
||||
|
||||
// numbers
|
||||
ASSERT_EQUALS("signed int", typeOf("1;", "1", "test.c", &s));
|
||||
|
@ -7888,8 +7888,8 @@ private:
|
|||
settings.library.mPodTypes["char8_t"] = char8;
|
||||
settings.library.mPodTypes["char16_t"] = char16;
|
||||
settings.library.mPodTypes["char32_t"] = char32;
|
||||
settings.sizeof_short = 2;
|
||||
settings.sizeof_int = 4;
|
||||
settings.platform.sizeof_short = 2;
|
||||
settings.platform.sizeof_int = 4;
|
||||
|
||||
ASSERT_EQUALS("unsigned char", typeOf("u8'a';", "u8'a'", "test.cpp", &settings));
|
||||
ASSERT_EQUALS("unsigned short", typeOf("u'a';", "u'a'", "test.cpp", &settings));
|
||||
|
@ -7901,7 +7901,7 @@ private:
|
|||
{
|
||||
// PodType
|
||||
Settings settingsWin64;
|
||||
settingsWin64.platformType = Settings::Win64;
|
||||
settingsWin64.platform.type = cppcheck::Platform::Type::Win64;
|
||||
const Library::PodType u32 = { 4, 'u' };
|
||||
const Library::PodType podtype2 = { 0, 'u', Library::PodType::Type::INT };
|
||||
settingsWin64.library.mPodTypes["u32"] = u32;
|
||||
|
@ -7923,10 +7923,10 @@ private:
|
|||
{
|
||||
// PlatformType
|
||||
Settings settingsUnix32;
|
||||
settingsUnix32.platformType = Settings::Unix32;
|
||||
settingsUnix32.platform.type = cppcheck::Platform::Type::Unix32;
|
||||
Library::PlatformType s32;
|
||||
s32.mType = "int";
|
||||
settingsUnix32.library.mPlatforms[settingsUnix32.platformString()].mPlatformTypes["s32"] = s32;
|
||||
settingsUnix32.library.mPlatforms[settingsUnix32.platform.toString()].mPlatformTypes["s32"] = s32;
|
||||
ValueType vt;
|
||||
ASSERT_EQUALS(true, vt.fromLibraryType("s32", &settingsUnix32));
|
||||
ASSERT_EQUALS(ValueType::Type::INT, vt.type);
|
||||
|
@ -7934,10 +7934,10 @@ private:
|
|||
{
|
||||
// PlatformType - wchar_t
|
||||
Settings settingsWin64;
|
||||
settingsWin64.platformType = Settings::Win64;
|
||||
settingsWin64.platform.type = cppcheck::Platform::Type::Win64;
|
||||
Library::PlatformType lpctstr;
|
||||
lpctstr.mType = "wchar_t";
|
||||
settingsWin64.library.mPlatforms[settingsWin64.platformString()].mPlatformTypes["LPCTSTR"] = lpctstr;
|
||||
settingsWin64.library.mPlatforms[settingsWin64.platform.toString()].mPlatformTypes["LPCTSTR"] = lpctstr;
|
||||
ValueType vt;
|
||||
ASSERT_EQUALS(true, vt.fromLibraryType("LPCTSTR", &settingsWin64));
|
||||
ASSERT_EQUALS(ValueType::Type::WCHAR_T, vt.type);
|
||||
|
|
|
@ -468,11 +468,11 @@ private:
|
|||
}
|
||||
|
||||
#define tokenizeAndStringify(...) tokenizeAndStringify_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
std::string tokenizeAndStringify_(const char* file, int linenr, const char code[], bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", Standards::cppstd_t std = Standards::CPP11) {
|
||||
std::string tokenizeAndStringify_(const char* file, int linenr, const char code[], bool expand = true, cppcheck::Platform::Type platform = cppcheck::Platform::Type::Native, const char* filename = "test.cpp", Standards::cppstd_t std = Standards::CPP11) {
|
||||
errout.str("");
|
||||
|
||||
settings1.debugwarnings = true;
|
||||
PLATFORM(settings1, platform);
|
||||
PLATFORM(settings1.platform, platform);
|
||||
settings1.standards.cpp = std;
|
||||
|
||||
// tokenize..
|
||||
|
@ -497,11 +497,11 @@ private:
|
|||
}
|
||||
|
||||
#define tokenizeAndStringifyWindows(...) tokenizeAndStringifyWindows_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
std::string tokenizeAndStringifyWindows_(const char* file, int linenr, const char code[], bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) {
|
||||
std::string tokenizeAndStringifyWindows_(const char* file, int linenr, const char code[], bool expand = true, cppcheck::Platform::Type platform = cppcheck::Platform::Type::Native, const char* filename = "test.cpp", bool cpp11 = true) {
|
||||
errout.str("");
|
||||
|
||||
settings_windows.debugwarnings = true;
|
||||
PLATFORM(settings_windows, platform);
|
||||
PLATFORM(settings_windows.platform, platform);
|
||||
settings_windows.standards.cpp = cpp11 ? Standards::CPP11 : Standards::CPP03;
|
||||
|
||||
// tokenize..
|
||||
|
@ -833,11 +833,11 @@ private:
|
|||
|
||||
void validate() {
|
||||
// C++ code in C file
|
||||
ASSERT_THROW(tokenizeAndStringify(";using namespace std;",false,Settings::Native,"test.c"), InternalError);
|
||||
ASSERT_THROW(tokenizeAndStringify(";std::map<int,int> m;",false,Settings::Native,"test.c"), InternalError);
|
||||
ASSERT_THROW(tokenizeAndStringify(";template<class T> class X { };",false,Settings::Native,"test.c"), InternalError);
|
||||
ASSERT_THROW(tokenizeAndStringify("int X<Y>() {};",false,Settings::Native,"test.c"), InternalError);
|
||||
ASSERT_THROW(tokenizeAndStringify("void foo(int i) { reinterpret_cast<char>(i) };",false,Settings::Native,"test.h"), InternalError);
|
||||
ASSERT_THROW(tokenizeAndStringify(";using namespace std;",false,cppcheck::Platform::Type::Native,"test.c"), InternalError);
|
||||
ASSERT_THROW(tokenizeAndStringify(";std::map<int,int> m;",false,cppcheck::Platform::Type::Native,"test.c"), InternalError);
|
||||
ASSERT_THROW(tokenizeAndStringify(";template<class T> class X { };",false,cppcheck::Platform::Type::Native,"test.c"), InternalError);
|
||||
ASSERT_THROW(tokenizeAndStringify("int X<Y>() {};",false,cppcheck::Platform::Type::Native,"test.c"), InternalError);
|
||||
ASSERT_THROW(tokenizeAndStringify("void foo(int i) { reinterpret_cast<char>(i) };",false,cppcheck::Platform::Type::Native,"test.h"), InternalError);
|
||||
}
|
||||
|
||||
void objectiveC() {
|
||||
|
@ -1794,7 +1794,7 @@ private:
|
|||
const char code[] = "struct foo {\n"
|
||||
" void operator delete(void *obj, size_t sz);\n"
|
||||
"}\n";
|
||||
const std::string actual(tokenizeAndStringify(code, true, Settings::Win32A));
|
||||
const std::string actual(tokenizeAndStringify(code, true, cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char expected[] = "struct foo {\n"
|
||||
"void operatordelete ( void * obj , unsigned long sz ) ;\n"
|
||||
|
@ -2275,7 +2275,7 @@ private:
|
|||
|
||||
void vardecl14() {
|
||||
const char code[] = "::std::tr1::shared_ptr<int> pNum1, pNum2;\n";
|
||||
ASSERT_EQUALS(":: std :: tr1 :: shared_ptr < int > pNum1 ; :: std :: tr1 :: shared_ptr < int > pNum2 ;", tokenizeAndStringify(code, false, Settings::Native, "test.cpp", Standards::CPP03));
|
||||
ASSERT_EQUALS(":: std :: tr1 :: shared_ptr < int > pNum1 ; :: std :: tr1 :: shared_ptr < int > pNum2 ;", tokenizeAndStringify(code, false, cppcheck::Platform::Type::Native, "test.cpp", Standards::CPP03));
|
||||
}
|
||||
|
||||
void vardecl15() {
|
||||
|
@ -2480,7 +2480,7 @@ private:
|
|||
void vardecl26() { // #5907
|
||||
const char code[] = "extern int *new, obj, player;";
|
||||
const char expected[] = "extern int * new ; extern int obj ; extern int player ;";
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
|
||||
}
|
||||
|
||||
|
@ -2491,7 +2491,7 @@ private:
|
|||
" return 0;\n"
|
||||
" return 0;\n"
|
||||
"}";
|
||||
tokenizeAndStringify(code, /*expand=*/ true, Settings::Native, "test.c");
|
||||
tokenizeAndStringify(code, /*expand=*/ true, cppcheck::Platform::Type::Native, "test.c");
|
||||
}
|
||||
|
||||
void vardecl28() {
|
||||
|
@ -2503,7 +2503,7 @@ private:
|
|||
"const unsigned short x ; x = 1 ;\n"
|
||||
"return x ;\n"
|
||||
"}",
|
||||
tokenizeAndStringify(code, /*expand=*/ true, Settings::Native, "test.c"));
|
||||
tokenizeAndStringify(code, /*expand=*/ true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
}
|
||||
|
||||
void vardecl29() { // #9282
|
||||
|
@ -2523,9 +2523,9 @@ private:
|
|||
void vardecl30() {
|
||||
const char code[] = "struct D {} const d;";
|
||||
ASSERT_EQUALS("struct D { } ; struct D const d ;",
|
||||
tokenizeAndStringify(code, true, Settings::Native, "test.cpp"));
|
||||
tokenizeAndStringify(code, true, cppcheck::Platform::Type::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("struct D { } ; struct D const d ;",
|
||||
tokenizeAndStringify(code, true, Settings::Native, "test.c"));
|
||||
tokenizeAndStringify(code, true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
}
|
||||
|
||||
void vardecl31() {
|
||||
|
@ -2596,15 +2596,15 @@ private:
|
|||
}
|
||||
|
||||
void implicitIntConst() {
|
||||
ASSERT_EQUALS("const int x ;", tokenizeAndStringify("const x;", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("const int * x ;", tokenizeAndStringify("const *x;", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("const int * f ( ) ;", tokenizeAndStringify("const *f();", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("const int x ;", tokenizeAndStringify("const x;", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
ASSERT_EQUALS("const int * x ;", tokenizeAndStringify("const *x;", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
ASSERT_EQUALS("const int * f ( ) ;", tokenizeAndStringify("const *f();", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
}
|
||||
|
||||
void implicitIntExtern() {
|
||||
ASSERT_EQUALS("extern int x ;", tokenizeAndStringify("extern x;", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("extern int * x ;", tokenizeAndStringify("extern *x;", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("const int * f ( ) ;", tokenizeAndStringify("const *f();", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("extern int x ;", tokenizeAndStringify("extern x;", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
ASSERT_EQUALS("extern int * x ;", tokenizeAndStringify("extern *x;", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
ASSERT_EQUALS("const int * f ( ) ;", tokenizeAndStringify("const *f();", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3549,15 +3549,15 @@ private:
|
|||
// Pointer to standard type
|
||||
ASSERT_EQUALS("char buf [ 100 ] ; readlink ( path , buf , 99 ) ;",
|
||||
tokenizeAndStringify("char buf[100] ; readlink(path, &buf[0], 99);",
|
||||
true, Settings::Native, "test.c"));
|
||||
true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
|
||||
ASSERT_EQUALS("void foo ( char * c ) { if ( 1 == ( 1 & c [ 0 ] ) ) { } }",
|
||||
tokenizeAndStringify("void foo(char *c) { if (1==(1 & c[0])) {} }",
|
||||
true, Settings::Native, "test.c"));
|
||||
true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
|
||||
// Simplification of unknown type - C only
|
||||
ASSERT_EQUALS("foo data [ 100 ] ; something ( foo ) ;",
|
||||
tokenizeAndStringify("foo data[100]; something(&foo[0]);", true, Settings::Native, "test.c"));
|
||||
tokenizeAndStringify("foo data[100]; something(&foo[0]);", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
|
||||
// C++: No pointer simplification
|
||||
ASSERT_EQUALS("foo data [ 100 ] ; something ( & foo [ 0 ] ) ;",
|
||||
|
@ -4280,16 +4280,16 @@ private:
|
|||
ASSERT_EQUALS("struct A { long x ; } ;", tokenizeAndStringify(code5));
|
||||
|
||||
const char code6[] = "struct A { __int8 x : 3; };";
|
||||
ASSERT_EQUALS("struct A { char x ; } ;", tokenizeAndStringifyWindows(code6, true, Settings::Win32A));
|
||||
ASSERT_EQUALS("struct A { char x ; } ;", tokenizeAndStringifyWindows(code6, true, cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code7[] = "struct A { __int16 x : 3; };";
|
||||
ASSERT_EQUALS("struct A { short x ; } ;", tokenizeAndStringifyWindows(code7, true, Settings::Win32A));
|
||||
ASSERT_EQUALS("struct A { short x ; } ;", tokenizeAndStringifyWindows(code7, true, cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code8[] = "struct A { __int32 x : 3; };";
|
||||
ASSERT_EQUALS("struct A { int x ; } ;", tokenizeAndStringifyWindows(code8, true, Settings::Win32A));
|
||||
ASSERT_EQUALS("struct A { int x ; } ;", tokenizeAndStringifyWindows(code8, true, cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code9[] = "struct A { __int64 x : 3; };";
|
||||
ASSERT_EQUALS("struct A { long long x ; } ;", tokenizeAndStringifyWindows(code9, true, Settings::Win32A));
|
||||
ASSERT_EQUALS("struct A { long long x ; } ;", tokenizeAndStringifyWindows(code9, true, cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code10[] = "struct A { unsigned char x : 3; };";
|
||||
ASSERT_EQUALS("struct A { unsigned char x ; } ;", tokenizeAndStringify(code10));
|
||||
|
@ -4304,16 +4304,16 @@ private:
|
|||
ASSERT_EQUALS("struct A { unsigned long x ; } ;", tokenizeAndStringify(code13));
|
||||
|
||||
const char code14[] = "struct A { unsigned __int8 x : 3; };";
|
||||
ASSERT_EQUALS("struct A { unsigned char x ; } ;", tokenizeAndStringifyWindows(code14, true, Settings::Win32A));
|
||||
ASSERT_EQUALS("struct A { unsigned char x ; } ;", tokenizeAndStringifyWindows(code14, true, cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code15[] = "struct A { unsigned __int16 x : 3; };";
|
||||
ASSERT_EQUALS("struct A { unsigned short x ; } ;", tokenizeAndStringifyWindows(code15, true, Settings::Win32A));
|
||||
ASSERT_EQUALS("struct A { unsigned short x ; } ;", tokenizeAndStringifyWindows(code15, true, cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code16[] = "struct A { unsigned __int32 x : 3; };";
|
||||
ASSERT_EQUALS("struct A { unsigned int x ; } ;", tokenizeAndStringifyWindows(code16, true, Settings::Win32A));
|
||||
ASSERT_EQUALS("struct A { unsigned int x ; } ;", tokenizeAndStringifyWindows(code16, true, cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code17[] = "struct A { unsigned __int64 x : 3; };";
|
||||
ASSERT_EQUALS("struct A { unsigned long long x ; } ;", tokenizeAndStringifyWindows(code17, true, Settings::Win32A));
|
||||
ASSERT_EQUALS("struct A { unsigned long long x ; } ;", tokenizeAndStringifyWindows(code17, true, cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code18[] = "struct A { signed char x : 3; };";
|
||||
ASSERT_EQUALS("struct A { signed char x ; } ;", tokenizeAndStringify(code18));
|
||||
|
@ -4328,16 +4328,16 @@ private:
|
|||
ASSERT_EQUALS("struct A { signed long x ; } ;", tokenizeAndStringifyWindows(code21));
|
||||
|
||||
const char code22[] = "struct A { signed __int8 x : 3; };";
|
||||
ASSERT_EQUALS("struct A { signed char x ; } ;", tokenizeAndStringifyWindows(code22, true, Settings::Win32A));
|
||||
ASSERT_EQUALS("struct A { signed char x ; } ;", tokenizeAndStringifyWindows(code22, true, cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code23[] = "struct A { signed __int16 x : 3; };";
|
||||
ASSERT_EQUALS("struct A { signed short x ; } ;", tokenizeAndStringifyWindows(code23, true, Settings::Win32A));
|
||||
ASSERT_EQUALS("struct A { signed short x ; } ;", tokenizeAndStringifyWindows(code23, true, cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code24[] = "struct A { signed __int32 x : 3; };";
|
||||
ASSERT_EQUALS("struct A { signed int x ; } ;", tokenizeAndStringifyWindows(code24, true, Settings::Win32A));
|
||||
ASSERT_EQUALS("struct A { signed int x ; } ;", tokenizeAndStringifyWindows(code24, true, cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code25[] = "struct A { signed __int64 x : 3; };";
|
||||
ASSERT_EQUALS("struct A { signed long long x ; } ;", tokenizeAndStringifyWindows(code25, true, Settings::Win32A));
|
||||
ASSERT_EQUALS("struct A { signed long long x ; } ;", tokenizeAndStringifyWindows(code25, true, cppcheck::Platform::Type::Win32A));
|
||||
}
|
||||
|
||||
void bitfields2() {
|
||||
|
@ -4554,11 +4554,11 @@ private:
|
|||
|
||||
code = "using namespace std;\n"
|
||||
"tr1::function <void(int)> f;";
|
||||
ASSERT_EQUALS("tr1 :: function < void ( int ) > f ;", tokenizeAndStringify(code, true, Settings::Native, "test.cpp", Standards::CPP03));
|
||||
ASSERT_EQUALS("tr1 :: function < void ( int ) > f ;", tokenizeAndStringify(code, true, cppcheck::Platform::Type::Native, "test.cpp", Standards::CPP03));
|
||||
ASSERT_EQUALS("std :: function < void ( int ) > f ;", tokenizeAndStringify(code));
|
||||
|
||||
code = "std::tr1::function <void(int)> f;";
|
||||
ASSERT_EQUALS("std :: tr1 :: function < void ( int ) > f ;", tokenizeAndStringify(code, true, Settings::Native, "test.cpp", Standards::CPP03));
|
||||
ASSERT_EQUALS("std :: tr1 :: function < void ( int ) > f ;", tokenizeAndStringify(code, true, cppcheck::Platform::Type::Native, "test.cpp", Standards::CPP03));
|
||||
ASSERT_EQUALS("std :: function < void ( int ) > f ;", tokenizeAndStringify(code));
|
||||
|
||||
// #4042 (Do not add 'std ::' to variables)
|
||||
|
@ -4634,72 +4634,72 @@ private:
|
|||
|
||||
void microsoftMemory() {
|
||||
const char code1a[] = "void foo() { int a[10], b[10]; CopyMemory(a, b, sizeof(a)); }";
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memcpy ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code1a,true,Settings::Win32A));
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memcpy ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code1a,true,cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code1b[] = "void foo() { int a[10], b[10]; RtlCopyMemory(a, b, sizeof(a)); }";
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memcpy ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code1b,true,Settings::Win32A));
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memcpy ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code1b,true,cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code1c[] = "void foo() { int a[10], b[10]; RtlCopyBytes(a, b, sizeof(a)); }";
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memcpy ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code1c,true,Settings::Win32A));
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memcpy ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code1c,true,cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code2a[] = "void foo() { int a[10]; FillMemory(a, sizeof(a), 255); }";
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 255 , sizeof ( a ) ) ; }", tokenizeAndStringify(code2a,true,Settings::Win32A));
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 255 , sizeof ( a ) ) ; }", tokenizeAndStringify(code2a,true,cppcheck::Platform::Type::Win32A));
|
||||
const char code2b[] = "void foo() { int a[10]; RtlFillMemory(a, sizeof(a), 255); }";
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 255 , sizeof ( a ) ) ; }", tokenizeAndStringify(code2b,true,Settings::Win32A));
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 255 , sizeof ( a ) ) ; }", tokenizeAndStringify(code2b,true,cppcheck::Platform::Type::Win32A));
|
||||
const char code2c[] = "void foo() { int a[10]; RtlFillBytes(a, sizeof(a), 255); }";
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 255 , sizeof ( a ) ) ; }", tokenizeAndStringify(code2c,true,Settings::Win32A));
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 255 , sizeof ( a ) ) ; }", tokenizeAndStringify(code2c,true,cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code3a[] = "void foo() { int a[10], b[10]; MoveMemory(a, b, sizeof(a)); }";
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memmove ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code3a,true,Settings::Win32A));
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memmove ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code3a,true,cppcheck::Platform::Type::Win32A));
|
||||
const char code3b[] = "void foo() { int a[10], b[10]; RtlMoveMemory(a, b, sizeof(a)); }";
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memmove ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code3b,true,Settings::Win32A));
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memmove ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code3b,true,cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code4a[] = "void foo() { int a[10]; ZeroMemory(a, sizeof(a)); }";
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 0 , sizeof ( a ) ) ; }", tokenizeAndStringify(code4a,true,Settings::Win32A));
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 0 , sizeof ( a ) ) ; }", tokenizeAndStringify(code4a,true,cppcheck::Platform::Type::Win32A));
|
||||
const char code4b[] = "void foo() { int a[10]; RtlZeroMemory(a, sizeof(a)); }";
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 0 , sizeof ( a ) ) ; }", tokenizeAndStringify(code4b,true,Settings::Win32A));
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 0 , sizeof ( a ) ) ; }", tokenizeAndStringify(code4b,true,cppcheck::Platform::Type::Win32A));
|
||||
const char code4c[] = "void foo() { int a[10]; RtlZeroBytes(a, sizeof(a)); }";
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 0 , sizeof ( a ) ) ; }", tokenizeAndStringify(code4c,true,Settings::Win32A));
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 0 , sizeof ( a ) ) ; }", tokenizeAndStringify(code4c,true,cppcheck::Platform::Type::Win32A));
|
||||
const char code4d[] = "void foo() { int a[10]; RtlSecureZeroMemory(a, sizeof(a)); }";
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 0 , sizeof ( a ) ) ; }", tokenizeAndStringify(code4d,true,Settings::Win32A));
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; memset ( a , 0 , sizeof ( a ) ) ; }", tokenizeAndStringify(code4d,true,cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code5[] = "void foo() { int a[10], b[10]; RtlCompareMemory(a, b, sizeof(a)); }";
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memcmp ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code5,true,Settings::Win32A));
|
||||
ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memcmp ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code5,true,cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code6[] = "void foo() { ZeroMemory(f(1, g(a, b)), h(i, j(0, 1))); }";
|
||||
ASSERT_EQUALS("void foo ( ) { memset ( f ( 1 , g ( a , b ) ) , 0 , h ( i , j ( 0 , 1 ) ) ) ; }", tokenizeAndStringify(code6,true,Settings::Win32A));
|
||||
ASSERT_EQUALS("void foo ( ) { memset ( f ( 1 , g ( a , b ) ) , 0 , h ( i , j ( 0 , 1 ) ) ) ; }", tokenizeAndStringify(code6,true,cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code7[] = "void foo() { FillMemory(f(1, g(a, b)), h(i, j(0, 1)), 255); }";
|
||||
ASSERT_EQUALS("void foo ( ) { memset ( f ( 1 , g ( a , b ) ) , 255 , h ( i , j ( 0 , 1 ) ) ) ; }", tokenizeAndStringify(code7,true,Settings::Win32A));
|
||||
ASSERT_EQUALS("void foo ( ) { memset ( f ( 1 , g ( a , b ) ) , 255 , h ( i , j ( 0 , 1 ) ) ) ; }", tokenizeAndStringify(code7,true,cppcheck::Platform::Type::Win32A));
|
||||
}
|
||||
|
||||
void microsoftString() {
|
||||
const char code1a[] = "void foo() { _tprintf (_T(\"test\") _T(\"1\")); }";
|
||||
ASSERT_EQUALS("void foo ( ) { printf ( \"test1\" ) ; }", tokenizeAndStringify(code1a, true, Settings::Win32A));
|
||||
ASSERT_EQUALS("void foo ( ) { printf ( \"test1\" ) ; }", tokenizeAndStringify(code1a, true, cppcheck::Platform::Type::Win32A));
|
||||
const char code1b[] = "void foo() { _tprintf (_TEXT(\"test\") _TEXT(\"2\")); }";
|
||||
ASSERT_EQUALS("void foo ( ) { printf ( \"test2\" ) ; }", tokenizeAndStringify(code1b, true, Settings::Win32A));
|
||||
ASSERT_EQUALS("void foo ( ) { printf ( \"test2\" ) ; }", tokenizeAndStringify(code1b, true, cppcheck::Platform::Type::Win32A));
|
||||
const char code1c[] = "void foo() { _tprintf (TEXT(\"test\") TEXT(\"3\")); }";
|
||||
ASSERT_EQUALS("void foo ( ) { printf ( \"test3\" ) ; }", tokenizeAndStringify(code1c, true, Settings::Win32A));
|
||||
ASSERT_EQUALS("void foo ( ) { printf ( \"test3\" ) ; }", tokenizeAndStringify(code1c, true, cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code2a[] = "void foo() { _tprintf (_T(\"test\") _T(\"1\")); }";
|
||||
ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test1\" ) ; }", tokenizeAndStringify(code2a, true, Settings::Win32W));
|
||||
ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test1\" ) ; }", tokenizeAndStringify(code2a, true, Settings::Win64));
|
||||
ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test1\" ) ; }", tokenizeAndStringify(code2a, true, cppcheck::Platform::Type::Win32W));
|
||||
ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test1\" ) ; }", tokenizeAndStringify(code2a, true, cppcheck::Platform::Type::Win64));
|
||||
const char code2b[] = "void foo() { _tprintf (_TEXT(\"test\") _TEXT(\"2\")); }";
|
||||
ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test2\" ) ; }", tokenizeAndStringify(code2b, true, Settings::Win32W));
|
||||
ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test2\" ) ; }", tokenizeAndStringify(code2b, true, Settings::Win64));
|
||||
ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test2\" ) ; }", tokenizeAndStringify(code2b, true, cppcheck::Platform::Type::Win32W));
|
||||
ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test2\" ) ; }", tokenizeAndStringify(code2b, true, cppcheck::Platform::Type::Win64));
|
||||
const char code2c[] = "void foo() { _tprintf (TEXT(\"test\") TEXT(\"3\")); }";
|
||||
ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test3\" ) ; }", tokenizeAndStringify(code2c, true, Settings::Win32W));
|
||||
ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test3\" ) ; }", tokenizeAndStringify(code2c, true, Settings::Win64));
|
||||
ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test3\" ) ; }", tokenizeAndStringify(code2c, true, cppcheck::Platform::Type::Win32W));
|
||||
ASSERT_EQUALS("void foo ( ) { wprintf ( L\"test3\" ) ; }", tokenizeAndStringify(code2c, true, cppcheck::Platform::Type::Win64));
|
||||
}
|
||||
|
||||
void borland() {
|
||||
// __closure
|
||||
ASSERT_EQUALS("int ( * a ) ( ) ;", // TODO VarId
|
||||
tokenizeAndStringify("int (__closure *a)();", true, Settings::Win32A));
|
||||
tokenizeAndStringify("int (__closure *a)();", true, cppcheck::Platform::Type::Win32A));
|
||||
|
||||
// __property
|
||||
ASSERT_EQUALS("class Fred { ; __property ; } ;",
|
||||
tokenizeAndStringify("class Fred { __property int x = { } };", true, Settings::Win32A));
|
||||
tokenizeAndStringify("class Fred { __property int x = { } };", true, cppcheck::Platform::Type::Win32A));
|
||||
}
|
||||
|
||||
void simplifySQL() {
|
||||
|
@ -4722,42 +4722,42 @@ private:
|
|||
}
|
||||
|
||||
void simplifyCAlternativeTokens() {
|
||||
ASSERT_EQUALS("void or ( ) ;", tokenizeAndStringify("void or(void);", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a && b ) { ; } }", tokenizeAndStringify("void f() { if (a and b); }", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a && b ) { ; } }", tokenizeAndStringify("void f() { if (a and b); }", true, Settings::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a || b ) { ; } }", tokenizeAndStringify("void f() { if (a or b); }", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a || b ) { ; } }", tokenizeAndStringify("void f() { if (a or b); }", true, Settings::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a & b ) { ; } }", tokenizeAndStringify("void f() { if (a bitand b); }", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a & b ) { ; } }", tokenizeAndStringify("void f() { if (a bitand b); }", true, Settings::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a | b ) { ; } }", tokenizeAndStringify("void f() { if (a bitor b); }", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a | b ) { ; } }", tokenizeAndStringify("void f() { if (a bitor b); }", true, Settings::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a ^ b ) { ; } }", tokenizeAndStringify("void f() { if (a xor b); }", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a ^ b ) { ; } }", tokenizeAndStringify("void f() { if (a xor b); }", true, Settings::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( ~ b ) { ; } }", tokenizeAndStringify("void f() { if (compl b); }", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( ~ b ) { ; } }", tokenizeAndStringify("void f() { if (compl b); }", true, Settings::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( ! b ) { ; } }", tokenizeAndStringify("void f() { if (not b); }", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( ! b ) { ; } }", tokenizeAndStringify("void f() { if (not b); }", true, Settings::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) const { if ( ! b ) { ; } }", tokenizeAndStringify("void f() const { if (not b); }", true, Settings::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a != b ) { ; } }", tokenizeAndStringify("void f() { if (a not_eq b); }", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a != b ) { ; } }", tokenizeAndStringify("void f() { if (a not_eq b); }", true, Settings::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void or ( ) ;", tokenizeAndStringify("void or(void);", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a && b ) { ; } }", tokenizeAndStringify("void f() { if (a and b); }", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a && b ) { ; } }", tokenizeAndStringify("void f() { if (a and b); }", true, cppcheck::Platform::Type::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a || b ) { ; } }", tokenizeAndStringify("void f() { if (a or b); }", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a || b ) { ; } }", tokenizeAndStringify("void f() { if (a or b); }", true, cppcheck::Platform::Type::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a & b ) { ; } }", tokenizeAndStringify("void f() { if (a bitand b); }", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a & b ) { ; } }", tokenizeAndStringify("void f() { if (a bitand b); }", true, cppcheck::Platform::Type::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a | b ) { ; } }", tokenizeAndStringify("void f() { if (a bitor b); }", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a | b ) { ; } }", tokenizeAndStringify("void f() { if (a bitor b); }", true, cppcheck::Platform::Type::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a ^ b ) { ; } }", tokenizeAndStringify("void f() { if (a xor b); }", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a ^ b ) { ; } }", tokenizeAndStringify("void f() { if (a xor b); }", true, cppcheck::Platform::Type::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( ~ b ) { ; } }", tokenizeAndStringify("void f() { if (compl b); }", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( ~ b ) { ; } }", tokenizeAndStringify("void f() { if (compl b); }", true, cppcheck::Platform::Type::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( ! b ) { ; } }", tokenizeAndStringify("void f() { if (not b); }", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( ! b ) { ; } }", tokenizeAndStringify("void f() { if (not b); }", true, cppcheck::Platform::Type::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) const { if ( ! b ) { ; } }", tokenizeAndStringify("void f() const { if (not b); }", true, cppcheck::Platform::Type::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a != b ) { ; } }", tokenizeAndStringify("void f() { if (a not_eq b); }", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a != b ) { ; } }", tokenizeAndStringify("void f() { if (a not_eq b); }", true, cppcheck::Platform::Type::Native, "test.cpp"));
|
||||
// #6201
|
||||
ASSERT_EQUALS("void f ( ) { if ( ! c || ! memcmp ( a , b , s ) ) { ; } }", tokenizeAndStringify("void f() { if (!c or !memcmp(a, b, s)); }", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( ! c || ! memcmp ( a , b , s ) ) { ; } }", tokenizeAndStringify("void f() { if (!c or !memcmp(a, b, s)); }", true, Settings::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( ! c || ! memcmp ( a , b , s ) ) { ; } }", tokenizeAndStringify("void f() { if (!c or !memcmp(a, b, s)); }", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( ! c || ! memcmp ( a , b , s ) ) { ; } }", tokenizeAndStringify("void f() { if (!c or !memcmp(a, b, s)); }", true, cppcheck::Platform::Type::Native, "test.cpp"));
|
||||
// #6029
|
||||
ASSERT_EQUALS("void f ( ) { if ( ! b ) { } }", tokenizeAndStringify("void f() { if (not b){} }", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( ! b ) { } }", tokenizeAndStringify("void f() { if (not b){} }", true, Settings::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( ! b ) { } }", tokenizeAndStringify("void f() { if (not b){} }", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( ! b ) { } }", tokenizeAndStringify("void f() { if (not b){} }", true, cppcheck::Platform::Type::Native, "test.cpp"));
|
||||
// #6207
|
||||
ASSERT_EQUALS("void f ( ) { if ( not = x ) { } }", tokenizeAndStringify("void f() { if (not=x){} }", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( not = x ) { } }", tokenizeAndStringify("void f() { if (not=x){} }", true, Settings::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( not = x ) { } }", tokenizeAndStringify("void f() { if (not=x){} }", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( not = x ) { } }", tokenizeAndStringify("void f() { if (not=x){} }", true, cppcheck::Platform::Type::Native, "test.cpp"));
|
||||
// #8029
|
||||
ASSERT_EQUALS("void f ( struct S * s ) { x = s . and + 1 ; }", tokenizeAndStringify("void f(struct S *s) { x = s->and + 1; }", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( struct S * s ) { x = s . and + 1 ; }", tokenizeAndStringify("void f(struct S *s) { x = s->and + 1; }", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
// #8745
|
||||
ASSERT_EQUALS("void f ( ) { if ( x ) { or = 0 ; } }", tokenizeAndStringify("void f() { if (x) or = 0; }"));
|
||||
// #9324
|
||||
ASSERT_EQUALS("void f ( const char * str ) { while ( * str == '!' || * str == '[' ) { } }",
|
||||
tokenizeAndStringify("void f(const char *str) { while (*str=='!' or *str=='['){} }"));
|
||||
// #9920
|
||||
ASSERT_EQUALS("result = ch != s . end ( ) && * ch == ':' ;", tokenizeAndStringify("result = ch != s.end() and *ch == ':';", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("result = ch != s . end ( ) && * ch == ':' ;", tokenizeAndStringify("result = ch != s.end() and *ch == ':';", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
|
||||
// #8975
|
||||
ASSERT_EQUALS("void foo ( ) {\n"
|
||||
|
@ -4768,9 +4768,9 @@ private:
|
|||
"void foo() {\n"
|
||||
" char *or;\n"
|
||||
" while ((*or != 0) && (*or != '|')) or++;\n"
|
||||
"}", true, Settings::Native, "test.c"));
|
||||
"}", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
// #10013
|
||||
ASSERT_EQUALS("void f ( ) { x = ! 123 ; }", tokenizeAndStringify("void f() { x = not 123; }", true, Settings::Native, "test.cpp"));
|
||||
ASSERT_EQUALS("void f ( ) { x = ! 123 ; }", tokenizeAndStringify("void f() { x = not 123; }", true, cppcheck::Platform::Type::Native, "test.cpp"));
|
||||
}
|
||||
|
||||
void simplifyRoundCurlyParentheses() {
|
||||
|
@ -4792,7 +4792,7 @@ private:
|
|||
"operator ( ) ; "
|
||||
"}";
|
||||
|
||||
ASSERT_EQUALS(result, tokenizeAndStringify(code, /*expand=*/ true, /*platform=*/ Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS(result, tokenizeAndStringify(code, /*expand=*/ true, /*platform=*/ cppcheck::Platform::Type::Native, "test.c"));
|
||||
}
|
||||
|
||||
void simplifyOperatorName2() {
|
||||
|
@ -5433,10 +5433,10 @@ private:
|
|||
"float * ptrToFloat ;";
|
||||
|
||||
// These types should be defined the same on all Windows platforms
|
||||
const std::string win32A = tokenizeAndStringifyWindows(code, true, Settings::Win32A);
|
||||
const std::string win32A = tokenizeAndStringifyWindows(code, true, cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS(expected, win32A);
|
||||
ASSERT_EQUALS(win32A, tokenizeAndStringifyWindows(code, true, Settings::Win32W));
|
||||
ASSERT_EQUALS(win32A, tokenizeAndStringifyWindows(code, true, Settings::Win64));
|
||||
ASSERT_EQUALS(win32A, tokenizeAndStringifyWindows(code, true, cppcheck::Platform::Type::Win32W));
|
||||
ASSERT_EQUALS(win32A, tokenizeAndStringifyWindows(code, true, cppcheck::Platform::Type::Win64));
|
||||
}
|
||||
|
||||
void platformWin32A() {
|
||||
|
@ -5482,7 +5482,7 @@ private:
|
|||
"sscanf ( dst , \"%s\" , dst ) ; "
|
||||
"} "
|
||||
"unsigned char tbyte ;";
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringifyWindows(code, true, Settings::Win32A));
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringifyWindows(code, true, cppcheck::Platform::Type::Win32A));
|
||||
}
|
||||
|
||||
void platformWin32W() {
|
||||
|
@ -5528,29 +5528,29 @@ private:
|
|||
"wscanf ( L\"%s\" , dst ) ; "
|
||||
"swscanf ( dst , L\"%s\" , dst ) ; "
|
||||
"}";
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringifyWindows(code, true, Settings::Win32W));
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringifyWindows(code, true, cppcheck::Platform::Type::Win32W));
|
||||
}
|
||||
|
||||
void platformWin32AStringCat() { //#5150
|
||||
const char code[] = "TCHAR text[] = _T(\"123\") _T(\"456\") _T(\"789\");";
|
||||
const char expected[] = "char text [ 10 ] = \"123456789\" ;";
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringifyWindows(code, true, Settings::Win32A));
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringifyWindows(code, true, cppcheck::Platform::Type::Win32A));
|
||||
}
|
||||
|
||||
void platformWin32WStringCat() { //#5150
|
||||
const char code[] = "TCHAR text[] = _T(\"123\") _T(\"456\") _T(\"789\");";
|
||||
const char expected[] = "wchar_t text [ 10 ] = L\"123456789\" ;";
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringifyWindows(code, true, Settings::Win32W));
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringifyWindows(code, true, cppcheck::Platform::Type::Win32W));
|
||||
}
|
||||
|
||||
void platformWinWithNamespace() {
|
||||
const char code1[] = "UINT32 a; ::UINT32 b; foo::UINT32 c;";
|
||||
const char expected1[] = "unsigned int a ; unsigned int b ; foo :: UINT32 c ;";
|
||||
ASSERT_EQUALS(expected1, tokenizeAndStringifyWindows(code1, true, Settings::Win32A));
|
||||
ASSERT_EQUALS(expected1, tokenizeAndStringifyWindows(code1, true, cppcheck::Platform::Type::Win32A));
|
||||
|
||||
const char code2[] = "LPCVOID a; ::LPCVOID b; foo::LPCVOID c;";
|
||||
const char expected2[] = "const void * a ; const void * b ; foo :: LPCVOID c ;";
|
||||
ASSERT_EQUALS(expected2, tokenizeAndStringifyWindows(code2, true, Settings::Win32A));
|
||||
ASSERT_EQUALS(expected2, tokenizeAndStringifyWindows(code2, true, cppcheck::Platform::Type::Win32A));
|
||||
}
|
||||
|
||||
void isOneNumber() const {
|
||||
|
@ -5634,10 +5634,10 @@ private:
|
|||
tokenizeAndStringify("[[deprecated]] int f();"));
|
||||
|
||||
ASSERT_EQUALS("[ [ deprecated ] ] int f ( ) ;",
|
||||
tokenizeAndStringify("[[deprecated]] int f();", true, Settings::Native, "test.cpp", Standards::CPP03));
|
||||
tokenizeAndStringify("[[deprecated]] int f();", true, cppcheck::Platform::Type::Native, "test.cpp", Standards::CPP03));
|
||||
|
||||
ASSERT_EQUALS("[ [ deprecated ] ] int f ( ) ;",
|
||||
tokenizeAndStringify("[[deprecated]] int f();", true, Settings::Native, "test.c"));
|
||||
tokenizeAndStringify("[[deprecated]] int f();", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
|
||||
ASSERT_EQUALS("template < class T > int f ( ) { }",
|
||||
tokenizeAndStringify("template <class T> [[noreturn]] int f(){}"));
|
||||
|
@ -5646,7 +5646,7 @@ private:
|
|||
tokenizeAndStringify("[[maybe_unused]] int f([[maybe_unused]] int i);"));
|
||||
|
||||
ASSERT_EQUALS("[ [ maybe_unused ] ] int f ( [ [ maybe_unused ] ] int i ) ;",
|
||||
tokenizeAndStringify("[[maybe_unused]] int f([[maybe_unused]] int i);", true, Settings::Native, "test.cpp", Standards::CPP03));
|
||||
tokenizeAndStringify("[[maybe_unused]] int f([[maybe_unused]] int i);", true, cppcheck::Platform::Type::Native, "test.cpp", Standards::CPP03));
|
||||
|
||||
ASSERT_EQUALS("struct a ;",
|
||||
tokenizeAndStringify("struct [[]] a;"));
|
||||
|
@ -6482,7 +6482,7 @@ private:
|
|||
" return y;\n"
|
||||
" else\n"
|
||||
" return z;\n"
|
||||
"}\n", true, Settings::Native, "test.cpp", Standards::CPP17));
|
||||
"}\n", true, cppcheck::Platform::Type::Native, "test.cpp", Standards::CPP17));
|
||||
|
||||
// #10079 - createInnerAST bug..
|
||||
ASSERT_EQUALS("x{([= yz= switchy(",
|
||||
|
@ -6630,7 +6630,7 @@ private:
|
|||
ASSERT_EQUALS("class Fred : Base { } ;", tokenizeAndStringify("class Fred FINAL : Base { } ;"));
|
||||
ASSERT_EQUALS("class Fred : Base { } ;", tokenizeAndStringify("class DLLEXPORT Fred final : Base { } ;")); // #11422
|
||||
// Regression for C code:
|
||||
ASSERT_EQUALS("struct Fred { } ;", tokenizeAndStringify("struct DLLEXPORT Fred { } ;", true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("struct Fred { } ;", tokenizeAndStringify("struct DLLEXPORT Fred { } ;", true, cppcheck::Platform::Type::Native, "test.c"));
|
||||
}
|
||||
|
||||
void sizeofAddParentheses() {
|
||||
|
@ -6764,7 +6764,7 @@ private:
|
|||
ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { assert(a+()); }"), InternalError, "syntax error: +()");
|
||||
|
||||
// #9445 - typeof is not a keyword in C
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("void foo() { char *typeof, *value; }", false, Settings::Native, "test.c"));
|
||||
ASSERT_NO_THROW(tokenizeAndStringify("void foo() { char *typeof, *value; }", false, cppcheck::Platform::Type::Native, "test.c"));
|
||||
|
||||
ASSERT_THROW_EQUALS(tokenizeAndStringify("enum : { };"), InternalError, "syntax error: Unexpected token '{'");
|
||||
ASSERT_THROW_EQUALS(tokenizeAndStringify("enum : 3 { };"), InternalError, "syntax error: Unexpected token '3'");
|
||||
|
|
|
@ -48,7 +48,7 @@ private:
|
|||
|
||||
void testaddtoken2() {
|
||||
const std::string code = "0xF0000000";
|
||||
settings.int_bit = 32;
|
||||
settings.platform.int_bit = 32;
|
||||
TokenList tokenlist(&settings);
|
||||
tokenlist.addtoken(code, 1, 1, false);
|
||||
ASSERT_EQUALS("0xF0000000", tokenlist.front()->str());
|
||||
|
|
|
@ -65,7 +65,7 @@ private:
|
|||
void checkTooBigShift_Unix32() {
|
||||
Settings settings0;
|
||||
Settings settings;
|
||||
PLATFORM(settings, Settings::Unix32);
|
||||
PLATFORM(settings.platform, cppcheck::Platform::Type::Unix32);
|
||||
|
||||
// unsigned types getting promoted to int sizeof(int) = 4 bytes
|
||||
// and unsigned types having already a size of 4 bytes
|
||||
|
@ -239,7 +239,7 @@ private:
|
|||
|
||||
void checkIntegerOverflow() {
|
||||
Settings settings;
|
||||
PLATFORM(settings, Settings::Unix32);
|
||||
PLATFORM(settings.platform, cppcheck::Platform::Type::Unix32);
|
||||
settings.severity.enable(Severity::warning);
|
||||
|
||||
check("x = (int)0x10000 * (int)0x10000;", &settings);
|
||||
|
@ -282,7 +282,7 @@ private:
|
|||
void signConversion() {
|
||||
Settings settings0;
|
||||
Settings settings;
|
||||
PLATFORM(settings, Settings::Unix64);
|
||||
PLATFORM(settings.platform, cppcheck::Platform::Type::Unix64);
|
||||
check("x = -4 * (unsigned)y;", &settings0);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (warning) Expression '-4' has a negative value. That is converted to an unsigned value and used in an unsigned calculation.\n", errout.str());
|
||||
|
||||
|
@ -333,7 +333,7 @@ private:
|
|||
void longCastAssign() {
|
||||
Settings settings;
|
||||
settings.severity.enable(Severity::style);
|
||||
PLATFORM(settings, Settings::Unix64);
|
||||
PLATFORM(settings.platform, cppcheck::Platform::Type::Unix64);
|
||||
|
||||
check("long f(int x, int y) {\n"
|
||||
" const long ret = x * y;\n"
|
||||
|
|
|
@ -79,11 +79,11 @@ private:
|
|||
}
|
||||
|
||||
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
void check_(const char* file, int line, const char code[], Settings::PlatformType platform = Settings::Native) {
|
||||
void check_(const char* file, int line, const char code[], cppcheck::Platform::Type platform = cppcheck::Platform::Type::Native) {
|
||||
// Clear the error buffer..
|
||||
errout.str("");
|
||||
|
||||
PLATFORM(settings, platform);
|
||||
PLATFORM(settings.platform, platform);
|
||||
|
||||
// Tokenize..
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
|
|
|
@ -92,11 +92,11 @@ private:
|
|||
}
|
||||
|
||||
|
||||
void check(const char code[], Settings::PlatformType platform = Settings::Native) {
|
||||
void check(const char code[], cppcheck::Platform::Type platform = cppcheck::Platform::Type::Native) {
|
||||
// Clear the error buffer..
|
||||
errout.str("");
|
||||
|
||||
PLATFORM(settings, platform);
|
||||
PLATFORM(settings.platform, platform);
|
||||
|
||||
// Raw tokens..
|
||||
std::vector<std::string> files(1, "test.cpp");
|
||||
|
@ -621,7 +621,7 @@ private:
|
|||
"public:\n"
|
||||
" Foo() { }\n"
|
||||
" __property int x = {read=getx}\n"
|
||||
"};", Settings::Win32A);
|
||||
"};", cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
@ -634,7 +634,7 @@ private:
|
|||
" }\n"
|
||||
"public:\n"
|
||||
" Foo() { }\n"
|
||||
"};", Settings::Win32A);
|
||||
"};", cppcheck::Platform::Type::Win32A);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
|
|
@ -989,7 +989,7 @@ private:
|
|||
|
||||
// ~
|
||||
code = "x = ~0U;";
|
||||
PLATFORM(settings, cppcheck::Platform::Native); // ensure platform is native
|
||||
PLATFORM(settings.platform, cppcheck::Platform::Type::Native); // ensure platform is native
|
||||
values = tokenValues(code,"~");
|
||||
ASSERT_EQUALS(1U, values.size());
|
||||
ASSERT_EQUALS(~0U, values.back().intvalue);
|
||||
|
@ -1165,26 +1165,26 @@ private:
|
|||
#define CHECK(A, B) CHECK3(A, B, A)
|
||||
|
||||
// standard types
|
||||
CHECK("void *", settings.sizeof_pointer);
|
||||
CHECK("void *", settings.platform.sizeof_pointer);
|
||||
CHECK("char", 1U);
|
||||
CHECK("short", settings.sizeof_short);
|
||||
CHECK("int", settings.sizeof_int);
|
||||
CHECK("long", settings.sizeof_long);
|
||||
CHECK3("long long", settings.sizeof_long_long, "long");
|
||||
CHECK("wchar_t", settings.sizeof_wchar_t);
|
||||
CHECK("float", settings.sizeof_float);
|
||||
CHECK("double", settings.sizeof_double);
|
||||
CHECK3("long double", settings.sizeof_long_double, "double");
|
||||
CHECK("short", settings.platform.sizeof_short);
|
||||
CHECK("int", settings.platform.sizeof_int);
|
||||
CHECK("long", settings.platform.sizeof_long);
|
||||
CHECK3("long long", settings.platform.sizeof_long_long, "long");
|
||||
CHECK("wchar_t", settings.platform.sizeof_wchar_t);
|
||||
CHECK("float", settings.platform.sizeof_float);
|
||||
CHECK("double", settings.platform.sizeof_double);
|
||||
CHECK3("long double", settings.platform.sizeof_long_double, "double");
|
||||
|
||||
// string/char literals
|
||||
CHECK("\"asdf\"", 5);
|
||||
CHECK("L\"asdf\"", 5 * settings.sizeof_wchar_t);
|
||||
CHECK("L\"asdf\"", 5 * settings.platform.sizeof_wchar_t);
|
||||
CHECK("u8\"asdf\"", 5); // char8_t
|
||||
CHECK("u\"asdf\"", 5 * 2); // char16_t
|
||||
CHECK("U\"asdf\"", 5 * 4); // char32_t
|
||||
CHECK("'a'", 1U);
|
||||
CHECK("'ab'", settings.sizeof_int);
|
||||
CHECK("L'a'", settings.sizeof_wchar_t);
|
||||
CHECK("'ab'", settings.platform.sizeof_int);
|
||||
CHECK("L'a'", settings.platform.sizeof_wchar_t);
|
||||
CHECK("u8'a'", 1U); // char8_t
|
||||
CHECK("u'a'", 2U); // char16_t
|
||||
CHECK("U'a'", 4U); // char32_t
|
||||
|
@ -1221,67 +1221,67 @@ private:
|
|||
} while (false)
|
||||
|
||||
// enums
|
||||
CHECK("", "", "E", settings.sizeof_int);
|
||||
CHECK("", "", "E", settings.platform.sizeof_int);
|
||||
|
||||
// typed enums
|
||||
CHECK("", ": char", "E", 1U);
|
||||
CHECK("", ": signed char", "E", 1U);
|
||||
CHECK("", ": unsigned char", "E", 1U);
|
||||
CHECK("", ": short", "E", settings.sizeof_short);
|
||||
CHECK("", ": signed short", "E", settings.sizeof_short);
|
||||
CHECK("", ": unsigned short", "E", settings.sizeof_short);
|
||||
CHECK("", ": int", "E", settings.sizeof_int);
|
||||
CHECK("", ": signed int", "E", settings.sizeof_int);
|
||||
CHECK("", ": unsigned int", "E", settings.sizeof_int);
|
||||
CHECK("", ": long", "E", settings.sizeof_long);
|
||||
CHECK("", ": signed long", "E", settings.sizeof_long);
|
||||
CHECK("", ": unsigned long", "E", settings.sizeof_long);
|
||||
CHECK("", ": long long", "E", settings.sizeof_long_long);
|
||||
CHECK("", ": signed long long", "E", settings.sizeof_long_long);
|
||||
CHECK("", ": unsigned long long", "E", settings.sizeof_long_long);
|
||||
CHECK("", ": wchar_t", "E", settings.sizeof_wchar_t);
|
||||
CHECK("", ": size_t", "E", settings.sizeof_size_t);
|
||||
CHECK("", ": short", "E", settings.platform.sizeof_short);
|
||||
CHECK("", ": signed short", "E", settings.platform.sizeof_short);
|
||||
CHECK("", ": unsigned short", "E", settings.platform.sizeof_short);
|
||||
CHECK("", ": int", "E", settings.platform.sizeof_int);
|
||||
CHECK("", ": signed int", "E", settings.platform.sizeof_int);
|
||||
CHECK("", ": unsigned int", "E", settings.platform.sizeof_int);
|
||||
CHECK("", ": long", "E", settings.platform.sizeof_long);
|
||||
CHECK("", ": signed long", "E", settings.platform.sizeof_long);
|
||||
CHECK("", ": unsigned long", "E", settings.platform.sizeof_long);
|
||||
CHECK("", ": long long", "E", settings.platform.sizeof_long_long);
|
||||
CHECK("", ": signed long long", "E", settings.platform.sizeof_long_long);
|
||||
CHECK("", ": unsigned long long", "E", settings.platform.sizeof_long_long);
|
||||
CHECK("", ": wchar_t", "E", settings.platform.sizeof_wchar_t);
|
||||
CHECK("", ": size_t", "E", settings.platform.sizeof_size_t);
|
||||
|
||||
// enumerators
|
||||
CHECK("", "", "E0", settings.sizeof_int);
|
||||
CHECK("", "", "E0", settings.platform.sizeof_int);
|
||||
|
||||
// typed enumerators
|
||||
CHECK("", ": char", "E0", 1U);
|
||||
CHECK("", ": signed char", "E0", 1U);
|
||||
CHECK("", ": unsigned char", "E0", 1U);
|
||||
CHECK("", ": short", "E0", settings.sizeof_short);
|
||||
CHECK("", ": signed short", "E0", settings.sizeof_short);
|
||||
CHECK("", ": unsigned short", "E0", settings.sizeof_short);
|
||||
CHECK("", ": int", "E0", settings.sizeof_int);
|
||||
CHECK("", ": signed int", "E0", settings.sizeof_int);
|
||||
CHECK("", ": unsigned int", "E0", settings.sizeof_int);
|
||||
CHECK("", ": long", "E0", settings.sizeof_long);
|
||||
CHECK("", ": signed long", "E0", settings.sizeof_long);
|
||||
CHECK("", ": unsigned long", "E0", settings.sizeof_long);
|
||||
CHECK("", ": long long", "E0", settings.sizeof_long_long);
|
||||
CHECK("", ": signed long long", "E0", settings.sizeof_long_long);
|
||||
CHECK("", ": unsigned long long", "E0", settings.sizeof_long_long);
|
||||
CHECK("", ": wchar_t", "E0", settings.sizeof_wchar_t);
|
||||
CHECK("", ": size_t", "E0", settings.sizeof_size_t);
|
||||
CHECK("", ": short", "E0", settings.platform.sizeof_short);
|
||||
CHECK("", ": signed short", "E0", settings.platform.sizeof_short);
|
||||
CHECK("", ": unsigned short", "E0", settings.platform.sizeof_short);
|
||||
CHECK("", ": int", "E0", settings.platform.sizeof_int);
|
||||
CHECK("", ": signed int", "E0", settings.platform.sizeof_int);
|
||||
CHECK("", ": unsigned int", "E0", settings.platform.sizeof_int);
|
||||
CHECK("", ": long", "E0", settings.platform.sizeof_long);
|
||||
CHECK("", ": signed long", "E0", settings.platform.sizeof_long);
|
||||
CHECK("", ": unsigned long", "E0", settings.platform.sizeof_long);
|
||||
CHECK("", ": long long", "E0", settings.platform.sizeof_long_long);
|
||||
CHECK("", ": signed long long", "E0", settings.platform.sizeof_long_long);
|
||||
CHECK("", ": unsigned long long", "E0", settings.platform.sizeof_long_long);
|
||||
CHECK("", ": wchar_t", "E0", settings.platform.sizeof_wchar_t);
|
||||
CHECK("", ": size_t", "E0", settings.platform.sizeof_size_t);
|
||||
|
||||
// class typed enumerators
|
||||
CHECK("class", ": char", "E :: E0", 1U);
|
||||
CHECK("class", ": signed char", "E :: E0", 1U);
|
||||
CHECK("class", ": unsigned char", "E :: E0", 1U);
|
||||
CHECK("class", ": short", "E :: E0", settings.sizeof_short);
|
||||
CHECK("class", ": signed short", "E :: E0", settings.sizeof_short);
|
||||
CHECK("class", ": unsigned short", "E :: E0", settings.sizeof_short);
|
||||
CHECK("class", ": int", "E :: E0", settings.sizeof_int);
|
||||
CHECK("class", ": signed int", "E :: E0", settings.sizeof_int);
|
||||
CHECK("class", ": unsigned int", "E :: E0", settings.sizeof_int);
|
||||
CHECK("class", ": long", "E :: E0", settings.sizeof_long);
|
||||
CHECK("class", ": signed long", "E :: E0", settings.sizeof_long);
|
||||
CHECK("class", ": unsigned long", "E :: E0", settings.sizeof_long);
|
||||
CHECK("class", ": long long", "E :: E0", settings.sizeof_long_long);
|
||||
CHECK("class", ": signed long long", "E :: E0", settings.sizeof_long_long);
|
||||
CHECK("class", ": unsigned long long", "E :: E0", settings.sizeof_long_long);
|
||||
CHECK("class", ": wchar_t", "E :: E0", settings.sizeof_wchar_t);
|
||||
CHECK("class", ": size_t", "E :: E0", settings.sizeof_size_t);
|
||||
CHECK("class", ": short", "E :: E0", settings.platform.sizeof_short);
|
||||
CHECK("class", ": signed short", "E :: E0", settings.platform.sizeof_short);
|
||||
CHECK("class", ": unsigned short", "E :: E0", settings.platform.sizeof_short);
|
||||
CHECK("class", ": int", "E :: E0", settings.platform.sizeof_int);
|
||||
CHECK("class", ": signed int", "E :: E0", settings.platform.sizeof_int);
|
||||
CHECK("class", ": unsigned int", "E :: E0", settings.platform.sizeof_int);
|
||||
CHECK("class", ": long", "E :: E0", settings.platform.sizeof_long);
|
||||
CHECK("class", ": signed long", "E :: E0", settings.platform.sizeof_long);
|
||||
CHECK("class", ": unsigned long", "E :: E0", settings.platform.sizeof_long);
|
||||
CHECK("class", ": long long", "E :: E0", settings.platform.sizeof_long_long);
|
||||
CHECK("class", ": signed long long", "E :: E0", settings.platform.sizeof_long_long);
|
||||
CHECK("class", ": unsigned long long", "E :: E0", settings.platform.sizeof_long_long);
|
||||
CHECK("class", ": wchar_t", "E :: E0", settings.platform.sizeof_wchar_t);
|
||||
CHECK("class", ": size_t", "E :: E0", settings.platform.sizeof_size_t);
|
||||
#undef CHECK
|
||||
|
||||
#define CHECK(A, B) \
|
||||
|
@ -1297,26 +1297,26 @@ private:
|
|||
} while (false)
|
||||
|
||||
// enum array
|
||||
CHECK("", settings.sizeof_int);
|
||||
CHECK("", settings.platform.sizeof_int);
|
||||
|
||||
// typed enum array
|
||||
CHECK(": char", 1U);
|
||||
CHECK(": signed char", 1U);
|
||||
CHECK(": unsigned char", 1U);
|
||||
CHECK(": short", settings.sizeof_short);
|
||||
CHECK(": signed short", settings.sizeof_short);
|
||||
CHECK(": unsigned short", settings.sizeof_short);
|
||||
CHECK(": int", settings.sizeof_int);
|
||||
CHECK(": signed int", settings.sizeof_int);
|
||||
CHECK(": unsigned int", settings.sizeof_int);
|
||||
CHECK(": long", settings.sizeof_long);
|
||||
CHECK(": signed long", settings.sizeof_long);
|
||||
CHECK(": unsigned long", settings.sizeof_long);
|
||||
CHECK(": long long", settings.sizeof_long_long);
|
||||
CHECK(": signed long long", settings.sizeof_long_long);
|
||||
CHECK(": unsigned long long", settings.sizeof_long_long);
|
||||
CHECK(": wchar_t", settings.sizeof_wchar_t);
|
||||
CHECK(": size_t", settings.sizeof_size_t);
|
||||
CHECK(": short", settings.platform.sizeof_short);
|
||||
CHECK(": signed short", settings.platform.sizeof_short);
|
||||
CHECK(": unsigned short", settings.platform.sizeof_short);
|
||||
CHECK(": int", settings.platform.sizeof_int);
|
||||
CHECK(": signed int", settings.platform.sizeof_int);
|
||||
CHECK(": unsigned int", settings.platform.sizeof_int);
|
||||
CHECK(": long", settings.platform.sizeof_long);
|
||||
CHECK(": signed long", settings.platform.sizeof_long);
|
||||
CHECK(": unsigned long", settings.platform.sizeof_long);
|
||||
CHECK(": long long", settings.platform.sizeof_long_long);
|
||||
CHECK(": signed long long", settings.platform.sizeof_long_long);
|
||||
CHECK(": unsigned long long", settings.platform.sizeof_long_long);
|
||||
CHECK(": wchar_t", settings.platform.sizeof_wchar_t);
|
||||
CHECK(": size_t", settings.platform.sizeof_size_t);
|
||||
#undef CHECK
|
||||
|
||||
#define CHECK(A, B) \
|
||||
|
@ -1332,26 +1332,26 @@ private:
|
|||
} while (false)
|
||||
|
||||
// enum array
|
||||
CHECK("", settings.sizeof_int);
|
||||
CHECK("", settings.platform.sizeof_int);
|
||||
|
||||
// typed enum array
|
||||
CHECK(": char", 1U);
|
||||
CHECK(": signed char", 1U);
|
||||
CHECK(": unsigned char", 1U);
|
||||
CHECK(": short", settings.sizeof_short);
|
||||
CHECK(": signed short", settings.sizeof_short);
|
||||
CHECK(": unsigned short", settings.sizeof_short);
|
||||
CHECK(": int", settings.sizeof_int);
|
||||
CHECK(": signed int", settings.sizeof_int);
|
||||
CHECK(": unsigned int", settings.sizeof_int);
|
||||
CHECK(": long", settings.sizeof_long);
|
||||
CHECK(": signed long", settings.sizeof_long);
|
||||
CHECK(": unsigned long", settings.sizeof_long);
|
||||
CHECK(": long long", settings.sizeof_long_long);
|
||||
CHECK(": signed long long", settings.sizeof_long_long);
|
||||
CHECK(": unsigned long long", settings.sizeof_long_long);
|
||||
CHECK(": wchar_t", settings.sizeof_wchar_t);
|
||||
CHECK(": size_t", settings.sizeof_size_t);
|
||||
CHECK(": short", settings.platform.sizeof_short);
|
||||
CHECK(": signed short", settings.platform.sizeof_short);
|
||||
CHECK(": unsigned short", settings.platform.sizeof_short);
|
||||
CHECK(": int", settings.platform.sizeof_int);
|
||||
CHECK(": signed int", settings.platform.sizeof_int);
|
||||
CHECK(": unsigned int", settings.platform.sizeof_int);
|
||||
CHECK(": long", settings.platform.sizeof_long);
|
||||
CHECK(": signed long", settings.platform.sizeof_long);
|
||||
CHECK(": unsigned long", settings.platform.sizeof_long);
|
||||
CHECK(": long long", settings.platform.sizeof_long_long);
|
||||
CHECK(": signed long long", settings.platform.sizeof_long_long);
|
||||
CHECK(": unsigned long long", settings.platform.sizeof_long_long);
|
||||
CHECK(": wchar_t", settings.platform.sizeof_wchar_t);
|
||||
CHECK(": size_t", settings.platform.sizeof_size_t);
|
||||
#undef CHECK
|
||||
|
||||
code = "uint16_t arr[10];\n"
|
||||
|
@ -3850,9 +3850,9 @@ private:
|
|||
const char *code;
|
||||
/* Set some temporary fixed values to simplify testing */
|
||||
const Settings settingsTmp = settings;
|
||||
settings.int_bit = 32;
|
||||
settings.long_bit = 64;
|
||||
settings.long_long_bit = MathLib::bigint_bits * 2;
|
||||
settings.platform.int_bit = 32;
|
||||
settings.platform.long_bit = 64;
|
||||
settings.platform.long_long_bit = MathLib::bigint_bits * 2;
|
||||
|
||||
code = "int f(int a) {\n"
|
||||
" int x = (a & 0xff) >> 16;\n"
|
||||
|
|
|
@ -33,7 +33,7 @@ struct InternalError;
|
|||
class TestVarID : public TestFixture {
|
||||
public:
|
||||
TestVarID() : TestFixture("TestVarID") {
|
||||
PLATFORM(settings, cppcheck::Platform::Unix64);
|
||||
PLATFORM(settings.platform, cppcheck::Platform::Type::Unix64);
|
||||
settings.standards.c = Standards::C89;
|
||||
settings.standards.cpp = Standards::CPPLatest;
|
||||
settings.checkUnusedTemplates = true;
|
||||
|
|
Loading…
Reference in New Issue