From: Jean-Marc Lasgouttes Date: Sun, 15 Sep 2019 22:43:35 +0000 (+0200) Subject: Many small code cleanups suggested by cppcheck X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=c6614d7f9d689cd03deb10d0872a10486aed7a8f;p=features.git Many small code cleanups suggested by cppcheck --- diff --git a/src/insets/InsetCollapsible.cpp b/src/insets/InsetCollapsible.cpp index 0420452bb9..755bb6c30b 100644 --- a/src/insets/InsetCollapsible.cpp +++ b/src/insets/InsetCollapsible.cpp @@ -65,7 +65,7 @@ InsetCollapsible::InsetCollapsible(InsetCollapsible const & rhs) } -InsetCollapsible const & InsetCollapsible::operator=(InsetCollapsible const & that) +InsetCollapsible & InsetCollapsible::operator=(InsetCollapsible const & that) { if (&that == this) return *this; diff --git a/src/insets/InsetCollapsible.h b/src/insets/InsetCollapsible.h index dac8440a5c..423f234987 100644 --- a/src/insets/InsetCollapsible.h +++ b/src/insets/InsetCollapsible.h @@ -39,7 +39,7 @@ public: /// InsetCollapsible(InsetCollapsible const & rhs); /// - InsetCollapsible const & operator=(InsetCollapsible const &); + InsetCollapsible & operator=(InsetCollapsible const &); /// virtual ~InsetCollapsible(); /// diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index 9d92681dd2..95e9af74d1 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -114,7 +114,7 @@ namespace lyx { // Lgb //FIXME: why do we set in stone the type here? -InsetFloat::InsetFloat(Buffer * buf, string params_str) +InsetFloat::InsetFloat(Buffer * buf, string const & params_str) : InsetCaptionable(buf) { string2params(params_str, params_); @@ -431,7 +431,7 @@ void InsetFloat::latex(otexstream & os, OutputParams const & runparams_in) const // sidewaysfloats always use their own page, // therefore don't output the p option that is always set if (!placement.empty() - && (!params_.sideways || (params_.sideways && from_ascii(placement) != "p"))) + && (!params_.sideways || from_ascii(placement) != "p")) os << '[' << from_ascii(placement) << ']'; os << '\n'; diff --git a/src/insets/InsetFloat.h b/src/insets/InsetFloat.h index 62b5873b90..224017e7ea 100644 --- a/src/insets/InsetFloat.h +++ b/src/insets/InsetFloat.h @@ -57,7 +57,7 @@ public: class InsetFloat : public InsetCaptionable { public: - InsetFloat(Buffer * buffer, std::string params_str); + InsetFloat(Buffer * buffer, std::string const & params_str); /// static void string2params(std::string const &, InsetFloatParams &); /// diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 0dead76939..3cf318906f 100755 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -883,15 +883,15 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const // If needed, use converters to produce a latex file from the child if (tmpwritefile != writefile) { ErrorList el; - Converters::RetVal const retval = + Converters::RetVal const conv_retval = theConverters().convert(tmp, tmpwritefile, writefile, included_file, inc_format, tex_format, el); - if (retval == Converters::KILLED && buffer().isClone() && + if (conv_retval == Converters::KILLED && buffer().isClone() && buffer().isExporting()) { // We really shouldn't get here, I don't think. LYXERR0("No conversion exception?"); throw ConversionException(); - } else if (retval != Converters::SUCCESS && !runparams.silent) { + } else if (conv_retval != Converters::SUCCESS && !runparams.silent) { docstring msg = bformat(_("Included file `%1$s' " "was not exported correctly.\n " "LaTeX export is probably incomplete."), diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp index 58cd25be5f..f0f731bff2 100644 --- a/src/insets/InsetInfo.cpp +++ b/src/insets/InsetInfo.cpp @@ -168,7 +168,7 @@ set getTexFileList(string const & filename) return list; } -bool translateString(docstring const in, docstring & out, string const lcode) +bool translateString(docstring const & in, docstring & out, string const & lcode) { out = translateIfPossible(in, lcode); return in != out; @@ -176,7 +176,7 @@ bool translateString(docstring const in, docstring & out, string const lcode) } // namespace anon -docstring InsetInfoParams::getDate(string const iname, QDate const date) const +docstring InsetInfoParams::getDate(string const & iname, QDate const date) const { QLocale loc; if (lang) @@ -201,7 +201,7 @@ docstring InsetInfoParams::getDate(string const iname, QDate const date) const } -docstring InsetInfoParams::getTime(string const iname, QTime const time) const +docstring InsetInfoParams::getTime(string const & iname, QTime const time) const { QLocale loc; if (lang) diff --git a/src/insets/InsetInfo.h b/src/insets/InsetInfo.h index 6fa080d2be..fa3cfda728 100644 --- a/src/insets/InsetInfo.h +++ b/src/insets/InsetInfo.h @@ -139,9 +139,9 @@ public: UNKNOWN_INFO, // Invalid type }; /// - docstring getDate(std::string const, QDate const date = QDate::currentDate()) const; + docstring getDate(std::string const &, QDate const date = QDate::currentDate()) const; /// - docstring getTime(std::string const, QTime const time = QTime::currentTime()) const; + docstring getTime(std::string const &, QTime const time = QTime::currentTime()) const; /// std::vector> getArguments(Buffer const * buf, std::string const &) const; diff --git a/src/insets/InsetQuotes.cpp b/src/insets/InsetQuotes.cpp index fca77e5c4d..d34efa48cd 100644 --- a/src/insets/InsetQuotes.cpp +++ b/src/insets/InsetQuotes.cpp @@ -111,10 +111,9 @@ InsetQuotesParams::QuoteStyle InsetQuotesParams::getQuoteStyle(string const & s, str = "eld"; } - int i; - // '.' wildcard means: keep current style if (!allow_wildcards || str[0] != '.') { + int i; for (i = 0; i < stylescount(); ++i) { if (str[0] == style_char[i]) { res = QuoteStyle(i); @@ -144,10 +143,9 @@ InsetQuotesParams::QuoteSide InsetQuotesParams::getQuoteSide(string const & s, str = "eld"; } - int i; - // '.' wildcard means: keep current side if (!allow_wildcards || str[1] != '.') { + int i; for (i = 0; i < 2; ++i) { if (str[1] == side_char[i]) { res = InsetQuotesParams::QuoteSide(i); @@ -177,10 +175,9 @@ InsetQuotesParams::QuoteLevel InsetQuotesParams::getQuoteLevel(string const & s, str = "eld"; } - int i; - // '.' wildcard means: keep current level if (!allow_wildcards || str[2] != '.') { + int i; for (i = 0; i < 2; ++i) { if (str[2] == level_char[i]) { res = InsetQuotesParams::QuoteLevel(i); diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index f2073f6cdf..c7757f1673 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -86,10 +86,9 @@ InsetText::InsetText(Buffer * buf, UsePlain type) InsetText::InsetText(InsetText const & in) - : Inset(in), text_(this, in.text_) + : Inset(in), drawFrame_(in.drawFrame_), frame_color_(in.frame_color_), + text_(this, in.text_) { - drawFrame_ = in.drawFrame_; - frame_color_ = in.frame_color_; } @@ -1142,9 +1141,9 @@ bool InsetText::needsCProtection(bool const maintext, bool const fragile) const Paragraph const & par = pars[size_type(pit)]; if (par.needsCProtection(fragile)) return true; - docstring const pars = par.asString(); + docstring const par_str = par.asString(); for (int k = 0; k < nchars_escape; k++) { - if (contains(pars, chars_escape[k])) + if (contains(par_str, chars_escape[k])) return true; } }