@@ -255,36 +255,9 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedF
255
255
int CppCheckExecutor::check_internal (CppCheck& cppcheck)
256
256
{
257
257
Settings& settings = cppcheck.settings ();
258
- const bool std = tryLoadLibrary (settings.library , settings.exename , " std.cfg" );
259
258
260
- auto failed_lib = std::find_if (settings.libraries .begin (), settings.libraries .end (), [&](const std::string& lib) {
261
- return !tryLoadLibrary (settings.library , settings.exename , lib.c_str ());
262
- });
263
- if (failed_lib != settings.libraries .end ()) {
264
- const std::string msg (" Failed to load the library " + *failed_lib);
265
- const std::list<ErrorMessage::FileLocation> callstack;
266
- ErrorMessage errmsg (callstack, emptyString, Severity::information, msg, " failedToLoadCfg" , Certainty::normal );
267
- reportErr (errmsg);
259
+ if (!loadLibraries (settings))
268
260
return EXIT_FAILURE;
269
- }
270
-
271
- if (!std) {
272
- const std::list<ErrorMessage::FileLocation> callstack;
273
- const std::string msg (" Failed to load std.cfg. Your Cppcheck installation is broken, please re-install." );
274
- #ifdef FILESDIR
275
- const std::string details (" The Cppcheck binary was compiled with FILESDIR set to \" "
276
- FILESDIR " \" and will therefore search for "
277
- " std.cfg in " FILESDIR " /cfg." );
278
- #else
279
- const std::string cfgfolder (Path::fromNativeSeparators (Path::getPathFromFilename (settings.exename )) + " cfg" );
280
- const std::string details (" The Cppcheck binary was compiled without FILESDIR set. Either the "
281
- " std.cfg should be available in " + cfgfolder + " or the FILESDIR "
282
- " should be configured." );
283
- #endif
284
- ErrorMessage errmsg (callstack, emptyString, Severity::information, msg+" " +details, " failedToLoadCfg" , Certainty::normal );
285
- reportErr (errmsg);
286
- return EXIT_FAILURE;
287
- }
288
261
289
262
if (settings.reportProgress )
290
263
mLatestProgressOutputTime = std::time (nullptr );
@@ -341,6 +314,42 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck)
341
314
return 0 ;
342
315
}
343
316
317
+ bool CppCheckExecutor::loadLibraries (Settings& settings)
318
+ {
319
+ const bool std = tryLoadLibrary (settings.library , settings.exename , " std.cfg" );
320
+
321
+ const auto failed_lib = std::find_if (settings.libraries .begin (), settings.libraries .end (), [&](const std::string& lib) {
322
+ return !tryLoadLibrary (settings.library , settings.exename , lib.c_str ());
323
+ });
324
+ if (failed_lib != settings.libraries .end ()) {
325
+ const std::string msg (" Failed to load the library " + *failed_lib);
326
+ const std::list<ErrorMessage::FileLocation> callstack;
327
+ ErrorMessage errmsg (callstack, emptyString, Severity::information, msg, " failedToLoadCfg" , Certainty::normal );
328
+ reportErr (errmsg);
329
+ return false ;
330
+ }
331
+
332
+ if (!std) {
333
+ const std::list<ErrorMessage::FileLocation> callstack;
334
+ const std::string msg (" Failed to load std.cfg. Your Cppcheck installation is broken, please re-install." );
335
+ #ifdef FILESDIR
336
+ const std::string details (" The Cppcheck binary was compiled with FILESDIR set to \" "
337
+ FILESDIR " \" and will therefore search for "
338
+ " std.cfg in " FILESDIR " /cfg." );
339
+ #else
340
+ const std::string cfgfolder (Path::fromNativeSeparators (Path::getPathFromFilename (settings.exename )) + " cfg" );
341
+ const std::string details (" The Cppcheck binary was compiled without FILESDIR set. Either the "
342
+ " std.cfg should be available in " + cfgfolder + " or the FILESDIR "
343
+ " should be configured." );
344
+ #endif
345
+ ErrorMessage errmsg (callstack, emptyString, Severity::information, msg+" " +details, " failedToLoadCfg" , Certainty::normal );
346
+ reportErr (errmsg);
347
+ return false ;
348
+ }
349
+
350
+ return true ;
351
+ }
352
+
344
353
#ifdef _WIN32
345
354
// fix trac ticket #439 'Cppcheck reports wrong filename for filenames containing 8-bit ASCII'
346
355
static inline std::string ansiToOEM (const std::string &msg, bool doConvert)
0 commit comments