|
32 | 32 | #include <cstring> |
33 | 33 | #include <fstream> |
34 | 34 | #include <map> |
| 35 | +#include <stdexcept> |
35 | 36 |
|
36 | 37 | //--------------------------------------------------------------------------- |
37 | 38 |
|
@@ -297,44 +298,53 @@ unsigned int CppCheck::check() |
297 | 298 | if (_settings._errorsOnly == false) |
298 | 299 | _errorLogger->reportOut(std::string("Checking ") + fname + std::string("...")); |
299 | 300 |
|
300 | | - Preprocessor preprocessor; |
301 | | - std::list<std::string> configurations; |
302 | | - std::string filedata = ""; |
303 | | - if (_fileContents.size() > 0 && _fileContents.find(_filenames[c]) != _fileContents.end()) |
| 301 | + try |
304 | 302 | { |
305 | | - // File content was given as a string |
306 | | - std::istringstream iss(_fileContents[ _filenames[c] ]); |
307 | | - preprocessor.preprocess(iss, filedata, configurations, fname, _includePaths); |
308 | | - } |
309 | | - else |
310 | | - { |
311 | | - // Only file name was given, read the content from file |
312 | | - std::ifstream fin(fname.c_str()); |
313 | | - preprocessor.preprocess(fin, filedata, configurations, fname, _includePaths); |
314 | | - } |
| 303 | + Preprocessor preprocessor; |
| 304 | + std::list<std::string> configurations; |
| 305 | + std::string filedata = ""; |
315 | 306 |
|
316 | | - int checkCount = 0; |
317 | | - for (std::list<std::string>::const_iterator it = configurations.begin(); it != configurations.end(); ++it) |
318 | | - { |
319 | | - // Check only 12 first configurations, after that bail out, unless --force |
320 | | - // was used. |
321 | | - if (!_settings._force && checkCount > 11) |
| 307 | + if (_fileContents.size() > 0 && _fileContents.find(_filenames[c]) != _fileContents.end()) |
322 | 308 | { |
323 | | - if (_settings._errorsOnly == false) |
324 | | - _errorLogger->reportOut(std::string("Bailing out from checking ") + fname + ": Too many configurations. Recheck this file with --force if you want to check them all."); |
325 | | - |
326 | | - break; |
| 309 | + // File content was given as a string |
| 310 | + std::istringstream iss(_fileContents[ _filenames[c] ]); |
| 311 | + preprocessor.preprocess(iss, filedata, configurations, fname, _includePaths); |
327 | 312 | } |
| 313 | + else |
| 314 | + { |
| 315 | + // Only file name was given, read the content from file |
| 316 | + std::ifstream fin(fname.c_str()); |
| 317 | + preprocessor.preprocess(fin, filedata, configurations, fname, _includePaths); |
| 318 | + } |
| 319 | + |
| 320 | + int checkCount = 0; |
| 321 | + for (std::list<std::string>::const_iterator it = configurations.begin(); it != configurations.end(); ++it) |
| 322 | + { |
| 323 | + // Check only 12 first configurations, after that bail out, unless --force |
| 324 | + // was used. |
| 325 | + if (!_settings._force && checkCount > 11) |
| 326 | + { |
| 327 | + if (_settings._errorsOnly == false) |
| 328 | + _errorLogger->reportOut(std::string("Bailing out from checking ") + fname + ": Too many configurations. Recheck this file with --force if you want to check them all."); |
| 329 | + |
| 330 | + break; |
| 331 | + } |
328 | 332 |
|
329 | | - cfg = *it; |
330 | | - std::string codeWithoutCfg = Preprocessor::getcode(filedata, *it, fname, _errorLogger); |
| 333 | + cfg = *it; |
| 334 | + std::string codeWithoutCfg = Preprocessor::getcode(filedata, *it, fname, _errorLogger); |
331 | 335 |
|
332 | | - // If only errors are printed, print filename after the check |
333 | | - if (_settings._errorsOnly == false && it != configurations.begin()) |
334 | | - _errorLogger->reportOut(std::string("Checking ") + fname + ": " + cfg + std::string("...")); |
| 336 | + // If only errors are printed, print filename after the check |
| 337 | + if (_settings._errorsOnly == false && it != configurations.begin()) |
| 338 | + _errorLogger->reportOut(std::string("Checking ") + fname + ": " + cfg + std::string("...")); |
335 | 339 |
|
336 | | - checkFile(codeWithoutCfg, _filenames[c].c_str()); |
337 | | - ++checkCount; |
| 340 | + checkFile(codeWithoutCfg, _filenames[c].c_str()); |
| 341 | + ++checkCount; |
| 342 | + } |
| 343 | + } |
| 344 | + catch (std::runtime_error &e) |
| 345 | + { |
| 346 | + // Exception was thrown when checking this file.. |
| 347 | + _errorLogger->reportOut("Bailing out from checking " + fname + ": " + e.what()); |
338 | 348 | } |
339 | 349 |
|
340 | 350 | _errorLogger->reportStatus(c + 1, _filenames.size()); |
|
0 commit comments