]> git.lyx.org Git - features.git/commitdiff
Various fixes suggested by cppcheck
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 13 Sep 2019 20:36:53 +0000 (22:36 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 13 Sep 2019 20:37:16 +0000 (22:37 +0200)
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
src/support/Package.cpp
src/support/Systemcall.cpp
src/support/lstrings.cpp
src/support/lstrings.h
src/support/os.cpp

index 7c47de0948c173f9a597a6e943c004e6e23e760e..42956b05b6f76f938c3e96b3b8ffd5ab83175c92 100644 (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);
index 284b5689daf93a77ab909a56d62e2a2a76a0a039..f931ddf7059bcbe0c28fba650b2d2aa0e3dede12 100644 (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.
index ae224cbf8c509411e62d08fb5c606996d1131eeb..a270b4118dbfc59584518317b37bc948b525e7c3 100644 (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");
index e2f3d9c0848322c92fb985bd08b7c18713600080..55e66ce077f717ab3ba71a343a1ff15e54e0848b 100644 (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;
 }
index ff0ce1d20738cd92a40584668faa32341bf5b60c..f661fc5b85abc1e635348b6a484e5944fe1a2b65 100644 (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);
index ab9d4159a6cc8180864e760f330af3fc95bbb5d7..10430bf5a2e756b766cf1c46e7279790f775d412 100644 (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 bin: 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 bin: list) {
                        string const binary = addName(localdir,
-                               bin.toLocal8Bit().constData());
+                               bin2.toLocal8Bit().constData());
                        command = python23_call(binary, true);
                        if (!command.empty())
                                return command;