Various fixes suggested by cppcheck

Rename local variables the hide other ones: get_binary_path, find_python_binary

Use unsigned int for conversion from hex using sscanf().

FileName::checksum(), parsecmd (SystemCall): use explcit values rather
than variable which value is known.
This commit is contained in:
Jean-Marc Lasgouttes 2019-09-13 22:36:53 +02:00
parent e3c5987806
commit 17c827d177
6 changed files with 20 additions and 20 deletions

View File

@ -548,16 +548,14 @@ unsigned long checksum_ifstream_fallback(char const * file)
unsigned long FileName::checksum() const
{
unsigned long result = 0;
if (!exists()) {
//LYXERR0("File \"" << absFileName() << "\" does not exist!");
return result;
return 0;
}
// a directory may be passed here so we need to test it. (bug 3622)
if (isDirectory()) {
LYXERR0('"' << absFileName() << "\" is a directory!");
return result;
return 0;
}
// This is used in the debug output at the end of the method.
@ -565,6 +563,8 @@ unsigned long FileName::checksum() const
if (lyxerr.debugging(Debug::FILES))
t.restart();
unsigned long result = 0;
#if QT_VERSION >= 0x999999
// First version of checksum uses Qt4.4 mmap support.
// FIXME: This code is not ready with Qt4.4.2,
@ -574,7 +574,7 @@ unsigned long FileName::checksum() const
// QAbstractFileEngine::MapExtension)
QFile qf(fi.filePath());
if (!qf.open(QIODevice::ReadOnly))
return result;
return 0;
qint64 size = fi.size();
uchar * ubeg = qf.map(0, size);
uchar * uend = ubeg + size;
@ -594,7 +594,7 @@ unsigned long FileName::checksum() const
int fd = open(file, O_RDONLY);
if (!fd)
return result;
return 0;
struct stat info;
if (fstat(fd, &info)){
@ -608,7 +608,7 @@ unsigned long FileName::checksum() const
// Some platforms have the wrong type for MAP_FAILED (compaq cxx).
if (mm == reinterpret_cast<void*>(MAP_FAILED)) {
close(fd);
return result;
return 0;
}
char * beg = static_cast<char*>(mm);

View File

@ -508,9 +508,9 @@ FileName const get_binary_path(string const & exe)
// This will do nothing if *it is already absolute.
string const exe_dir = makeAbsPath(*it).absFileName();
FileName const exe_path(addName(exe_dir, exe_name));
if (exe_path.exists())
return exe_path;
FileName const exe_path2(addName(exe_dir, exe_name));
if (exe_path2.exists())
return exe_path2;
}
// Didn't find anything.

View File

@ -205,7 +205,7 @@ string const parsecmd(string const & incmd, string & infile, string & outfile,
in_double_quote = !in_double_quote;
}
} else if (c == '\\' && !escaped) {
escaped = !escaped;
escaped = true;
} else if (c == '>' && !(in_double_quote || escaped)) {
if (suffixIs(outcmd[o], " 2")) {
outcmd[o] = rtrim(outcmd[o], "2");

View File

@ -422,10 +422,10 @@ bool isHex(docstring const & str)
}
int hexToInt(docstring const & str)
unsigned int hexToInt(docstring const & str)
{
string s = to_ascii(str);
int h;
unsigned int h;
sscanf(s.c_str(), "%x", &h);
return h;
}

View File

@ -53,7 +53,7 @@ bool isHexChar(char_type);
bool isHex(docstring const & str);
int hexToInt(docstring const & str);
unsigned int hexToInt(docstring const & str);
/// is \p str pure ascii?
bool isAscii(docstring const & str);

View File

@ -99,15 +99,15 @@ static string const find_python_binary()
// but we are trying hard to find a valid python binary
vector<string> const path = getEnvPath("PATH");
lyxerr << "Looking for python 3.x ...\n";
for (auto bin: path) {
for (auto bin : path) {
QString const dir = toqstr(bin);
string const localdir = dir.toLocal8Bit().constData();
QDir qdir(dir);
qdir.setFilter(QDir::Files | QDir::Executable);
QStringList list = qdir.entryList(QStringList("python3*"));
for (auto bin: list) {
for (auto bin2 : list) {
string const binary = addName(localdir,
bin.toLocal8Bit().constData());
bin2.toLocal8Bit().constData());
command = python23_call(binary, true);
if (!command.empty())
return command;
@ -123,15 +123,15 @@ static string const find_python_binary()
// the search is probably broader than required
// but we are trying hard to find a valid python binary
lyxerr << "Looking for python 2.x ...\n";
for (auto bin: path) {
for (auto bin : path) {
QString const dir = toqstr(bin);
string const localdir = dir.toLocal8Bit().constData();
QDir qdir(dir);
qdir.setFilter(QDir::Files | QDir::Executable);
QStringList list = qdir.entryList(QStringList("python2*"));
for (auto bin: list) {
for (auto bin2 : list) {
string const binary = addName(localdir,
bin.toLocal8Bit().constData());
bin2.toLocal8Bit().constData());
command = python23_call(binary, true);
if (!command.empty())
return command;