fix: (UB) get shared ptr from raw pointer

This commit is contained in:
Roy Qu 2024-05-03 07:50:05 +08:00
parent 2b029bc4cb
commit 1eb804ab0e
2 changed files with 13 additions and 9 deletions

View File

@ -989,7 +989,7 @@ bool CppParser::isSystemHeaderFile(const QString &fileName)
return ::isSystemHeaderFile(fileName,mPreprocessor.includePaths());
}
void CppParser::parseFile(const QString &fileName, bool inProject, bool onlyIfNotParsed, bool updateView)
void CppParser::parseFile(const QString &fileName, bool inProject, bool onlyIfNotParsed, bool updateView, std::weak_ptr<CppParser> parserPtr)
{
if (!mEnabled)
return;
@ -1001,6 +1001,7 @@ void CppParser::parseFile(const QString &fileName, bool inProject, bool onlyIfNo
mLastParseFileCommand->inProject = inProject;
mLastParseFileCommand->onlyIfNotParsed = onlyIfNotParsed;
mLastParseFileCommand->updateView = updateView;
mLastParseFileCommand->parserPtr = parserPtr;
return;
}
if (mLockCount>0)
@ -1020,8 +1021,9 @@ void CppParser::parseFile(const QString &fileName, bool inProject, bool onlyIfNo
emit onEndParsing(mFilesScannedCount,0);
if (mLastParseFileCommand) {
mParsing = false;
::parseFile(PCppParser{this},
PCppParser parser=mLastParseFileCommand->parserPtr.lock();
if (parser)
::parseFile(parser,
mLastParseFileCommand->fileName,
mLastParseFileCommand->inProject,
mLastParseFileCommand->onlyIfNotParsed,
@ -6768,7 +6770,7 @@ CppFileParserThread::CppFileParserThread(
void CppFileParserThread::run()
{
if (mParser) {
mParser->parseFile(mFileName,mInProject,mOnlyIfNotParsed,mUpdateView);
mParser->parseFile(mFileName,mInProject,mOnlyIfNotParsed,mUpdateView,mParser);
}
}

View File

@ -36,6 +36,7 @@ public:
bool inProject;
bool onlyIfNotParsed;
bool updateView;
std::weak_ptr<CppParser> parserPtr;
};
using PParseFileCommand = std::unique_ptr<ParseFileCommand>;
@ -119,7 +120,8 @@ public:
bool isProjectHeaderFile(const QString& fileName);
bool isSystemHeaderFile(const QString& fileName);
void parseFile(const QString& fileName, bool inProject,
bool onlyIfNotParsed = false, bool updateView = true);
bool onlyIfNotParsed = false, bool updateView = true,
std::weak_ptr<CppParser> parserPtr = nullptr);
void parseFileList(bool updateView = true);
void parseHardDefines();
bool parsing() const;