Library: Added configuration file std.cfg that clients should load.
This commit is contained in:
parent
941da42cfd
commit
0c5e39a813
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<def>
|
||||||
|
<memory>
|
||||||
|
<dealloc>free</dealloc>
|
||||||
|
|
||||||
|
<alloc init="false">malloc</alloc>
|
||||||
|
<alloc init="true">calloc</alloc>
|
||||||
|
<alloc init="true">strdup</alloc>
|
||||||
|
<alloc init="true">strndup</alloc>
|
||||||
|
</memory>
|
||||||
|
|
||||||
|
<resource>
|
||||||
|
<dealloc>fclose</dealloc>
|
||||||
|
<alloc init="false">fopen</alloc>
|
||||||
|
</resource>
|
||||||
|
</def>
|
||||||
|
|
|
@ -152,6 +152,8 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
|
||||||
Settings& settings = cppCheck.settings();
|
Settings& settings = cppCheck.settings();
|
||||||
_settings = &settings;
|
_settings = &settings;
|
||||||
|
|
||||||
|
settings.library.load(argv[0], "std");
|
||||||
|
|
||||||
if (!parseFromArgs(&cppCheck, argc, argv)) {
|
if (!parseFromArgs(&cppCheck, argc, argv)) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -516,6 +516,9 @@ Settings MainWindow::GetCppcheckSettings()
|
||||||
{
|
{
|
||||||
Settings result;
|
Settings result;
|
||||||
|
|
||||||
|
const QString applicationFilePath = QCoreApplication::applicationFilePath();
|
||||||
|
result.library.load(applicationFilePath.toLatin1(), "std");
|
||||||
|
|
||||||
// If project file loaded, read settings from it
|
// If project file loaded, read settings from it
|
||||||
if (mProject) {
|
if (mProject) {
|
||||||
ProjectFile *pfile = mProject->GetProjectFile();
|
ProjectFile *pfile = mProject->GetProjectFile();
|
||||||
|
|
|
@ -17,20 +17,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "library.h"
|
#include "library.h"
|
||||||
|
#include "path.h"
|
||||||
#include "tinyxml2.h"
|
#include "tinyxml2.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
Library::Library() : allocid(0)
|
Library::Library() : allocid(0)
|
||||||
{
|
{
|
||||||
while (!ismemory(++allocid));
|
|
||||||
_alloc["malloc"] = allocid;
|
|
||||||
_alloc["calloc"] = allocid;
|
|
||||||
_alloc["strdup"] = allocid;
|
|
||||||
_alloc["strndup"] = allocid;
|
|
||||||
_dealloc["free"] = allocid;
|
|
||||||
|
|
||||||
while (!isresource(++allocid));
|
|
||||||
_alloc["fopen"] = allocid;
|
|
||||||
_dealloc["fclose"] = allocid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Library::Library(const Library &lib) :
|
Library::Library(const Library &lib) :
|
||||||
|
@ -43,7 +37,6 @@ Library::Library(const Library &lib) :
|
||||||
_dealloc(lib._dealloc),
|
_dealloc(lib._dealloc),
|
||||||
_noreturn(lib._noreturn)
|
_noreturn(lib._noreturn)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Library::~Library() { }
|
Library::~Library() { }
|
||||||
|
@ -65,20 +58,28 @@ bool Library::load(const char exename[], const char path[])
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// open file..
|
||||||
FILE *fp = fopen(path, "rt");
|
FILE *fp = fopen(path, "rt");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
std::string fullpath(exename);
|
// failed to open file.. is there no extension?
|
||||||
if (fullpath.find_first_of("/\\") != std::string::npos)
|
std::string fullfilename(path);
|
||||||
fullpath = fullpath.substr(0, 1U + fullpath.find_last_of("/\\"));
|
if (Path::getFilenameExtension(fullfilename) == "") {
|
||||||
fullpath += path;
|
fullfilename += ".cfg";
|
||||||
fp = fopen(fullpath.c_str(), "rt");
|
fp = fopen(fullfilename.c_str(), "rt");
|
||||||
if (fp == NULL) {
|
}
|
||||||
fullpath += ".cfg";
|
|
||||||
fp = fopen(fullpath.c_str(), "rt");
|
if (fp==NULL) {
|
||||||
|
// Try to locate the library configuration in the installation folder..
|
||||||
|
std::string temp = exename;
|
||||||
|
std::replace(temp.begin(), temp.end(), '\\', '/');
|
||||||
|
const std::string installfolder = Path::getPathFromFilename(temp);
|
||||||
|
const std::string filename = installfolder + "cfg/" + fullfilename;
|
||||||
|
fp = fopen(filename.c_str(), "rt");
|
||||||
|
}
|
||||||
|
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (doc.LoadFile(fp) != tinyxml2::XML_NO_ERROR)
|
if (doc.LoadFile(fp) != tinyxml2::XML_NO_ERROR)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -48,6 +48,15 @@ public:
|
||||||
return getid(_dealloc, name);
|
return getid(_dealloc, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** set allocation id for function */
|
||||||
|
void setalloc(const std::string &functionname, int id) {
|
||||||
|
_alloc[functionname] = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setdealloc(const std::string &functionname, int id) {
|
||||||
|
_dealloc[functionname] = id;
|
||||||
|
}
|
||||||
|
|
||||||
/** is allocation type memory? */
|
/** is allocation type memory? */
|
||||||
static bool ismemory(int id) {
|
static bool ismemory(int id) {
|
||||||
return ((id > 0) && ((id & 1) == 0));
|
return ((id > 0) && ((id & 1) == 0));
|
||||||
|
|
|
@ -111,6 +111,13 @@ private:
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
int id = 0;
|
||||||
|
while (!settings.library.ismemory(++id));
|
||||||
|
settings.library.setalloc("malloc",id);
|
||||||
|
settings.library.setdealloc("free",id);
|
||||||
|
while (!settings.library.isresource(++id));
|
||||||
|
settings.library.setalloc("fopen",id);
|
||||||
|
settings.library.setdealloc("fclose",id);
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.c");
|
tokenizer.tokenize(istr, "test.c");
|
||||||
|
|
Loading…
Reference in New Issue