commit 17c827d1774cb8a73d2d1973261a83b695209386
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Fri Sep 13 22:36:53 2019 +0200
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.
---
src/support/FileName.cpp | 14 +++++++-------
src/support/Package.cpp | 6 +++---
src/support/Systemcall.cpp | 2 +-
src/support/lstrings.cpp | 4 ++--
src/support/lstrings.h | 2 +-
src/support/os.cpp | 12 ++++++------
6 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/src/support/FileName.cpp b/src/support/FileName.cpp
index 7c47de0..42956b0 100644
--- a/src/support/FileName.cpp
+++ b/src/support/FileName.cpp
@@ -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);
diff --git a/src/support/Package.cpp b/src/support/Package.cpp
index 284b568..f931ddf 100644
--- a/src/support/Package.cpp
+++ b/src/support/Package.cpp
@@ -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.
diff --git a/src/support/Systemcall.cpp b/src/support/Systemcall.cpp
index ae224cb..a270b41 100644
--- a/src/support/Systemcall.cpp
+++ b/src/support/Systemcall.cpp
@@ -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");
diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp
index e2f3d9c..55e66ce 100644
--- a/src/support/lstrings.cpp
+++ b/src/support/lstrings.cpp
@@ -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;
}
diff --git a/src/support/lstrings.h b/src/support/lstrings.h
index ff0ce1d..f661fc5 100644
--- a/src/support/lstrings.h
+++ b/src/support/lstrings.h
@@ -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);
diff --git a/src/support/os.cpp b/src/support/os.cpp
index ab9d415..10430bf 100644
--- a/src/support/os.cpp
+++ b/src/support/os.cpp
@@ -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;