Fixed #4612 (Adding file extensions to Cppcheck analysis)

This commit is contained in:
Daniel Marjamäki 2013-03-01 18:04:10 +01:00
parent dc88f20201
commit bcc0f87b4b
1 changed files with 19 additions and 23 deletions

View File

@ -69,39 +69,39 @@ static BOOL MyFileExists(const std::string& path)
void FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, const std::string &path) void FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, const std::string &path)
{ {
// oss is the search string passed into FindFirst and FindNext. const std::string cleanedPath = Path::toNativeSeparators(path);
// bdir is the base directory which is used to form pathnames.
// basedir is the base directory which is used to form pathnames.
// It always has a trailing backslash available for concatenation. // It always has a trailing backslash available for concatenation.
std::ostringstream bdir, oss; std::string basedir;
std::string cleanedPath = Path::toNativeSeparators(path); // searchPattern is the search string passed into FindFirst and FindNext.
std::string searchPattern = cleanedPath;
oss << cleanedPath;
if (MyIsDirectory(cleanedPath)) { if (MyIsDirectory(cleanedPath)) {
char c = cleanedPath[ cleanedPath.size()-1 ]; char c = cleanedPath[ cleanedPath.size()-1 ];
switch (c) { switch (c) {
case '\\': case '\\':
oss << '*'; searchPattern += '*';
bdir << cleanedPath; basedir = cleanedPath;
break; break;
case '*': case '*':
bdir << cleanedPath.substr(0, cleanedPath.length() - 1); basedir = cleanedPath.substr(0, cleanedPath.length() - 1);
break; break;
default: default:
oss << "\\*"; searchPattern += "\\*";
if (cleanedPath != ".") if (cleanedPath != ".")
bdir << cleanedPath << '\\'; basedir = cleanedPath + '\\';
} }
} else { } else {
std::string::size_type pos = cleanedPath.find_last_of('\\'); std::string::size_type pos = cleanedPath.find_last_of('\\');
if (std::string::npos != pos) { if (std::string::npos != pos) {
bdir << cleanedPath.substr(0, pos + 1); basedir = cleanedPath.substr(0, pos + 1);
} }
} }
WIN32_FIND_DATAA ffd; WIN32_FIND_DATAA ffd;
HANDLE hFind = MyFindFirstFile(oss.str(), &ffd); HANDLE hFind = MyFindFirstFile(searchPattern, &ffd);
if (INVALID_HANDLE_VALUE == hFind) if (INVALID_HANDLE_VALUE == hFind)
return; return;
@ -114,25 +114,21 @@ void FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, co
ansiFfd = ffd.cAlternateFileName; ansiFfd = ffd.cAlternateFileName;
} }
std::ostringstream fname; const std::string fname(basedir + ansiFfd);
fname << bdir.str() << ansiFfd;
if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
// File // File
const std::string nativename = Path::fromNativeSeparators(fname);
// If recursive is not used, accept all files given by user
if (Path::sameFileName(path, ansiFfd) || Path::acceptFile(ansiFfd)) {
const std::string nativename = Path::fromNativeSeparators(fname.str());
// Limitation: file sizes are assumed to fit in a 'size_t' // Limitation: file sizes are assumed to fit in a 'size_t'
#ifdef _WIN64 #ifdef _WIN64
files[nativename] = (static_cast<std::size_t>(ffd.nFileSizeHigh) << 32) | ffd.nFileSizeLow; files[nativename] = (static_cast<std::size_t>(ffd.nFileSizeHigh) << 32) | ffd.nFileSizeLow;
#else #else
files[nativename] = ffd.nFileSizeLow; files[nativename] = ffd.nFileSizeLow;
#endif #endif
}
} else { } else {
// Directory // Directory
FileLister::recursiveAddFiles(files, fname.str()); FileLister::recursiveAddFiles(files, fname);
} }
} while (FindNextFileA(hFind, &ffd) != FALSE); } while (FindNextFileA(hFind, &ffd) != FALSE);