]> git.lyx.org Git - lyx.git/commitdiff
Use auto const & when possible to avoid copies
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 30 Aug 2022 15:31:37 +0000 (17:31 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 30 Aug 2022 15:31:37 +0000 (17:31 +0200)
In several range-based for loops, implicit copies are made. Remove
that when possible, and try to shut converity up otherwise.

Fixes issues found by coverity.

src/BufferParams.cpp
src/frontends/qt/GuiApplication.cpp
src/insets/InsetInfo.cpp
src/lyxfind.cpp
src/support/os.cpp

index d25dd05bac2e55da31f0afe52be4446e7a0e0fb1..74270bba5c68c7583f98e680040c5d5a2c204e4b 100644 (file)
@@ -1979,6 +1979,8 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
        if (!features.runparams().includeall && !included_children_.empty()) {
                os << "\\includeonly{";
                bool first = true;
+               // we do not use "auto const &" here, because incfile is modified later
+               // coverity[auto_causes_copy]
                for (auto incfile : included_children_) {
                        FileName inc = makeAbsPath(incfile, filepath.absFileName());
                        string mangled = DocFileName(changeExtension(inc.absFileName(), ".tex")).
index 127a847944d6983c35f64e764917fdd236a5d749..ff33065fe34fe313fd051ef1d21227d614f02ec2 100644 (file)
@@ -556,7 +556,7 @@ QString getAlias(QString name) {
                has_aliases = true;
        }
        // check for the following aliases
-       for (auto alias : aliases) {
+       for (auto const & alias : aliases) {
                if (name.contains(alias.first))
                        name.replace(alias.first, alias.second);
        }
index 67aca81fe714ee556c44cd37ca4297224364f25b..ed2566eadb0c6785e7552d1782c0b036c0976c52 100644 (file)
@@ -159,6 +159,8 @@ set<string> getTexFileList(string const & filename)
                getVectorFromString(file.fileContents("UTF-8"), from_ascii("\n"));
 
        // Normalise paths like /foo//bar ==> /foo/bar
+       // No "auto const &" because doc is modified later
+       // coverity[auto_causes_copy]
        for (auto doc : doclist) {
                doc = subst(doc, from_ascii("\r"), docstring());
                while (contains(doc, from_ascii("//")))
index bce889b773904cf751a016060f04ca71d4b2407d..c8fc40947e75643cb281589fc41b62b30508858c 100644 (file)
@@ -2424,7 +2424,7 @@ void LatexInfo::buildEntries(bool isPatternString)
        }
        // Ignore language if there is math somewhere in pattern-string
        if (isPatternString) {
-               for (auto s: usedText) {
+               for (auto const & s: usedText) {
                        // Remove entries created in previous search runs
                        keys.erase(s);
                }
index 6561fbca38316dad669fc63ad5d609386763a9d4..407e1de4fc0182f256673fccad8f7033e64dc6f3 100644 (file)
@@ -111,13 +111,13 @@ 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 const & 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 bin2 : list) {
+               for (auto const & bin2 : list) {
                        string const binary = "\"" + addName(localdir,
                                bin2.toLocal8Bit().constData()) + "\"";
                        command = python23_call(binary, true);
@@ -155,13 +155,13 @@ static string const find_python_binary()
        QString const exeName = "python2*";
 #endif // _WIN32
 
-       for (auto bin : path) {
+       for (auto const & 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(exeName));
-               for (auto bin2 : list) {
+               for (auto const & bin2 : list) {
                        string const binary = "\"" + addName(localdir,
                                bin2.toLocal8Bit().constData()) + "\"";
                        command = python23_call(binary, true);