Fixed #9260 (--template=gcc does not work correctly with -j)
This commit is contained in:
parent
e07cb807e1
commit
a5ba82c2d3
|
@ -559,19 +559,15 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
|
||||||
|
|
||||||
} catch (const InternalError &e) {
|
} catch (const InternalError &e) {
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
|
||||||
if (e.token) {
|
if (e.token) {
|
||||||
loc.line = e.token->linenr();
|
ErrorLogger::ErrorMessage::FileLocation loc(e.token, &mTokenizer.list);
|
||||||
loc.column = e.token->column();
|
locationList.push_back(loc);
|
||||||
const std::string fixedpath = Path::toNativeSeparators(mTokenizer.list.file(e.token));
|
|
||||||
loc.setfile(fixedpath);
|
|
||||||
} else {
|
} else {
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc2;
|
ErrorLogger::ErrorMessage::FileLocation loc(mTokenizer.list.getSourceFilePath(), 0, 0);
|
||||||
loc2.setfile(Path::toNativeSeparators(filename));
|
ErrorLogger::ErrorMessage::FileLocation loc2(filename, 0, 0);
|
||||||
locationList.push_back(loc2);
|
locationList.push_back(loc2);
|
||||||
loc.setfile(mTokenizer.list.getSourceFilePath());
|
locationList.push_back(loc);
|
||||||
}
|
}
|
||||||
locationList.push_back(loc);
|
|
||||||
ErrorLogger::ErrorMessage errmsg(locationList,
|
ErrorLogger::ErrorMessage errmsg(locationList,
|
||||||
mTokenizer.list.getSourceFilePath(),
|
mTokenizer.list.getSourceFilePath(),
|
||||||
Severity::error,
|
Severity::error,
|
||||||
|
|
|
@ -247,7 +247,7 @@ std::string ErrorLogger::ErrorMessage::serialize() const
|
||||||
|
|
||||||
for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator loc = callStack.begin(); loc != callStack.end(); ++loc) {
|
for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator loc = callStack.begin(); loc != callStack.end(); ++loc) {
|
||||||
std::ostringstream smallStream;
|
std::ostringstream smallStream;
|
||||||
smallStream << (*loc).line << ':' << (*loc).column << ':' << (*loc).getfile() << '\t' << loc->getinfo();
|
smallStream << (*loc).line << '\t' << (*loc).column << '\t' << (*loc).getfile(false) << '\t' << loc->getOrigFile(false) << '\t' << loc->getinfo();
|
||||||
oss << smallStream.str().length() << " " << smallStream.str();
|
oss << smallStream.str().length() << " " << smallStream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,28 +309,29 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
|
||||||
temp.append(1, c);
|
temp.append(1, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string::size_type colonPos1 = temp.find(':');
|
std::vector<std::string> substrings;
|
||||||
if (colonPos1 == std::string::npos)
|
for (std::string::size_type pos = 0; pos < temp.size() && substrings.size() < 5; ++pos) {
|
||||||
throw InternalError(nullptr, "Internal Error: No colon found in <line:col:filename> pattern");
|
if (substrings.size() == 4) {
|
||||||
const std::string::size_type colonPos2 = temp.find(':', colonPos1+1);
|
substrings.push_back(temp.substr(pos));
|
||||||
if (colonPos2 == std::string::npos)
|
break;
|
||||||
throw InternalError(nullptr, "Internal Error: second colon not found in <line:col:filename> pattern");
|
}
|
||||||
const std::string::size_type tabPos = temp.find('\t');
|
const std::string::size_type start = pos;
|
||||||
if (tabPos == std::string::npos)
|
pos = temp.find("\t", pos);
|
||||||
throw InternalError(nullptr, "Internal Error: No tab found in <filename:line> pattern");
|
if (pos == std::string::npos) {
|
||||||
|
substrings.push_back(temp.substr(start));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
substrings.push_back(temp.substr(start, pos - start));
|
||||||
|
}
|
||||||
|
if (substrings.size() < 4)
|
||||||
|
throw InternalError(nullptr, "Internal Error: serializing/deserializing of error message failed!");
|
||||||
|
|
||||||
const std::string tempinfo = temp.substr(tabPos + 1);
|
// (*loc).line << '\t' << (*loc).column << '\t' << (*loc).getfile(false) << '\t' << loc->getOrigFile(false) << '\t' << loc->getinfo();
|
||||||
temp.erase(tabPos);
|
|
||||||
const std::string tempfile = temp.substr(colonPos2 + 1);
|
ErrorLogger::ErrorMessage::FileLocation loc(substrings[3], MathLib::toLongNumber(substrings[0]), MathLib::toLongNumber(substrings[1]));
|
||||||
temp.erase(colonPos2);
|
loc.setfile(substrings[2]);
|
||||||
const std::string tempcolumn = temp.substr(colonPos1 + 1);
|
if (substrings.size() == 5)
|
||||||
temp.erase(colonPos1);
|
loc.setinfo(substrings[4]);
|
||||||
const std::string templine = temp;
|
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
|
||||||
loc.setfile(tempfile);
|
|
||||||
loc.setinfo(tempinfo);
|
|
||||||
loc.column = MathLib::toLongNumber(tempcolumn);
|
|
||||||
loc.line = MathLib::toLongNumber(templine);
|
|
||||||
|
|
||||||
callStack.push_back(loc);
|
callStack.push_back(loc);
|
||||||
|
|
||||||
|
@ -441,7 +442,7 @@ void ErrorLogger::ErrorMessage::findAndReplace(std::string &source, const std::s
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: read info from some shared resource instead?
|
// TODO: read info from some shared resource instead?
|
||||||
static std::string readCode(const std::string &file, unsigned int linenr, unsigned int column, const char endl[])
|
static std::string readCode(const std::string &file, int linenr, int column, const char endl[])
|
||||||
{
|
{
|
||||||
std::ifstream fin(file);
|
std::ifstream fin(file);
|
||||||
std::string line;
|
std::string line;
|
||||||
|
|
|
@ -211,6 +211,11 @@ public:
|
||||||
*/
|
*/
|
||||||
std::string getfile(bool convert = true) const;
|
std::string getfile(bool convert = true) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filename with the whole path (no --rp)
|
||||||
|
* @param convert If true convert path to native separators.
|
||||||
|
* @return filename.
|
||||||
|
*/
|
||||||
std::string getOrigFile(bool convert = true) const;
|
std::string getOrigFile(bool convert = true) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -291,10 +291,8 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerializeFileLocation() const {
|
void SerializeFileLocation() const {
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc1;
|
ErrorLogger::ErrorMessage::FileLocation loc1(":/,;", 654, 33);
|
||||||
loc1.setfile(":/,");
|
loc1.setfile("[]:;,()");
|
||||||
loc1.line = 643;
|
|
||||||
loc1.column = 33;
|
|
||||||
loc1.setinfo("abcd:/,");
|
loc1.setinfo("abcd:/,");
|
||||||
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs{loc1};
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs{loc1};
|
||||||
|
@ -303,8 +301,9 @@ private:
|
||||||
|
|
||||||
ErrorMessage msg2;
|
ErrorMessage msg2;
|
||||||
msg2.deserialize(msg.serialize());
|
msg2.deserialize(msg.serialize());
|
||||||
ASSERT_EQUALS(":/,", msg2.callStack.front().getfile(false));
|
ASSERT_EQUALS("[]:;,()", msg2.callStack.front().getfile(false));
|
||||||
ASSERT_EQUALS(643, msg2.callStack.front().line);
|
ASSERT_EQUALS(":/,;", msg2.callStack.front().getOrigFile(false));
|
||||||
|
ASSERT_EQUALS(654, msg2.callStack.front().line);
|
||||||
ASSERT_EQUALS(33, msg2.callStack.front().column);
|
ASSERT_EQUALS(33, msg2.callStack.front().column);
|
||||||
ASSERT_EQUALS("abcd:/,", msg2.callStack.front().getinfo());
|
ASSERT_EQUALS("abcd:/,", msg2.callStack.front().getinfo());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue