@@ -884,6 +884,27 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
884884 return checkInternal (file, cfgname, fileIndex, f);
885885}
886886
887+ bool CppCheck::checkPlistOutput (const FileWithDetails& file, const std::vector<std::string>& files)
888+ {
889+ if (!mSettings .plistOutput .empty ()) {
890+ const bool slashFound = file.spath ().find (' /' ) != std::string::npos;
891+ std::string filename = slashFound ? file.spath ().substr (file.spath ().rfind (' /' ) + 1 ) : file.spath ();
892+ const std::size_t dotPosition = filename.find (' .' );
893+
894+ if (dotPosition == std::string::npos) {
895+ ErrorMessage::FileLocation loc (filename, 0 , 0 );
896+ ErrorMessage errmsg ({std::move (loc)}, " " , Severity::error, " filename does not contain dot" , " filenameError" , Certainty::normal);
897+ mErrorLogger .reportErr (errmsg);
898+ return false ;
899+ }
900+
901+ const std::size_t fileNameHash = std::hash<std::string> {}(file.spath ());
902+ filename = mSettings .plistOutput + filename.substr (0 , filename.find (' .' )) + " _" + std::to_string (fileNameHash) + " .plist" ;
903+ mLogger ->openPlist (filename, files);
904+ }
905+ return true ;
906+ }
907+
887908unsigned int CppCheck::checkInternal (const FileWithDetails& file, const std::string &cfgname, int fileIndex, const CreateTokenListFn& createTokenList)
888909{
889910 // TODO: move to constructor when CppCheck no longer owns the settings
@@ -989,16 +1010,8 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
9891010 if (!preprocessor.loadFiles (tokens1, files))
9901011 return mLogger ->exitcode ();
9911012
992- if (!mSettings .plistOutput .empty ()) {
993- std::string filename2;
994- if (file.spath ().find (' /' ) != std::string::npos)
995- filename2 = file.spath ().substr (file.spath ().rfind (' /' ) + 1 );
996- else
997- filename2 = file.spath ();
998- const std::size_t fileNameHash = std::hash<std::string> {}(file.spath ());
999- filename2 = mSettings .plistOutput + filename2.substr (0 , filename2.find (' .' )) + " _" + std::to_string (fileNameHash) + " .plist" ;
1000- mLogger ->openPlist (filename2, files);
1001- }
1013+ if (!checkPlistOutput (file, files))
1014+ return mLogger ->exitcode ();
10021015
10031016 std::string dumpProlog;
10041017 if (mSettings .dump || !mSettings .addons .empty ()) {
0 commit comments