[LyX/master] Refactoring based on cppcheck suggestions
Jean-Marc Lasgouttes
lasgouttes at lyx.org
Sat Oct 3 11:12:19 UTC 2020
commit 715b8cda54a2aded29260b57ff201b16fd906f21
Author: Yuriy Skalko <yuriy.skalko at gmail.com>
Date: Thu Oct 1 13:34:15 2020 +0300
Refactoring based on cppcheck suggestions
---
src/Author.cpp | 3 +--
src/Buffer.cpp | 5 ++---
src/Compare.cpp | 3 +--
src/CutAndPaste.cpp | 4 ++--
src/CutAndPaste.h | 2 +-
src/LaTeX.cpp | 1 -
src/LaTeXFonts.cpp | 8 ++++----
src/Language.cpp | 6 +++---
src/Paragraph.cpp | 2 +-
src/Text.h | 6 +++---
src/Text2.cpp | 4 ++--
src/Text3.cpp | 4 ++--
src/TextMetrics.cpp | 4 ++--
src/TextMetrics.h | 2 +-
src/TocBackend.cpp | 2 +-
src/Trans.cpp | 4 +---
src/frontends/qt/FindAndReplace.cpp | 2 +-
src/frontends/qt/GuiBibtex.cpp | 2 +-
src/frontends/qt/GuiBibtex.h | 2 +-
src/frontends/qt/GuiBox.cpp | 4 ++--
src/frontends/qt/GuiCitation.cpp | 2 +-
src/frontends/qt/GuiCitation.h | 2 +-
src/frontends/qt/GuiLyXFiles.cpp | 2 +-
src/frontends/qt/GuiLyXFiles.h | 2 +-
src/lyxfind.cpp | 5 ++---
src/mathed/MathStream.cpp | 2 +-
src/output_latex.cpp | 2 +-
src/support/ForkedCalls.cpp | 2 +-
src/support/debug.cpp | 2 +-
src/support/docstring.cpp | 3 +--
src/support/filetools.cpp | 3 +--
src/support/unicode.cpp | 4 ++--
src/tex2lyx/Preamble.cpp | 1 -
src/tex2lyx/tex2lyx.h | 6 +++---
34 files changed, 49 insertions(+), 59 deletions(-)
diff --git a/src/Author.cpp b/src/Author.cpp
index e4f538d..9a2dc1e 100644
--- a/src/Author.cpp
+++ b/src/Author.cpp
@@ -53,8 +53,7 @@ docstring Author::nameAndEmail() const
{
if (email().empty())
return name();
- else
- return bformat(_("%1$s[[name]] (%2$s[[email]])"), name(), email());
+ return bformat(_("%1$s[[name]] (%2$s[[email]])"), name(), email());
}
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 3fe0b9b..40db4aa 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -1549,9 +1549,8 @@ bool Buffer::save() const
// time stamp is invalidated by copying/moving
saveCheckSum();
markClean();
- if (d->file_format != LYX_FORMAT)
- // the file associated with this buffer is now in the current format
- d->file_format = LYX_FORMAT;
+ // the file associated with this buffer is now in the current format
+ d->file_format = LYX_FORMAT;
return true;
}
// else we saved the file, but failed to move it to the right location.
diff --git a/src/Compare.cpp b/src/Compare.cpp
index 68bd632..aaadf82 100644
--- a/src/Compare.cpp
+++ b/src/Compare.cpp
@@ -232,7 +232,7 @@ public:
///
Impl(Compare const & compare)
: abort_(false), n_(0), m_(0), offset_reverse_diagonal_(0),
- odd_offset_(0), compare_(compare),
+ odd_offset_(false), compare_(compare),
old_buf_(nullptr), new_buf_(nullptr), dest_buf_(nullptr),
dest_pars_(nullptr), recursion_level_(0), nested_inset_level_(0), D_(0)
{}
@@ -413,7 +413,6 @@ void Compare::run()
static_cast<InsetText &>(dest_buffer->inset()), el);
finished(pimpl_->abort_);
- return;
}
diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp
index 09cedf8..0d91b98 100644
--- a/src/CutAndPaste.cpp
+++ b/src/CutAndPaste.cpp
@@ -737,7 +737,7 @@ void region(CursorSlice const & i1, CursorSlice const & i2,
Inset::row_type & r1, Inset::row_type & r2,
Inset::col_type & c1, Inset::col_type & c2)
{
- Inset & p = i1.inset();
+ Inset const & p = i1.inset();
c1 = p.col(i1.idx());
c2 = p.col(i2.idx());
if (c1 > c2)
@@ -1079,7 +1079,7 @@ void copySelectionToStack()
}
-void copySelectionToTemp(Cursor & cur)
+void copySelectionToTemp(Cursor const & cur)
{
copySelectionToStack(cur, tempCut);
}
diff --git a/src/CutAndPaste.h b/src/CutAndPaste.h
index a67d1b5..a6ce3fc 100644
--- a/src/CutAndPaste.h
+++ b/src/CutAndPaste.h
@@ -66,7 +66,7 @@ void cutSelectionToTemp(Cursor & cur, bool realcut = true);
/// Push the current selection to the cut buffer and the system clipboard.
void copySelection(Cursor const & cur);
/// Like copySelection, but only put to temporary cut buffer
-void copySelectionToTemp(Cursor & cur);
+void copySelectionToTemp(Cursor const & cur);
///
void copyInset(Cursor const & cur, Inset * inset, docstring const & plaintext);
/**
diff --git a/src/LaTeX.cpp b/src/LaTeX.cpp
index f5b6d20..e88184b 100644
--- a/src/LaTeX.cpp
+++ b/src/LaTeX.cpp
@@ -1648,7 +1648,6 @@ int LaTeX::scanIlgFile(TeXErrors & terr)
string prevtoken;
while (getline(ifs, token)) {
token = rtrim(token, "\r");
- smatch sub;
if (prefixIs(token, "!! "))
prevtoken = token;
else if (!prevtoken.empty()) {
diff --git a/src/LaTeXFonts.cpp b/src/LaTeXFonts.cpp
index 00e19fa..cb68634 100644
--- a/src/LaTeXFonts.cpp
+++ b/src/LaTeXFonts.cpp
@@ -522,10 +522,10 @@ bool LaTeXFont::readFont(Lexer & lex)
bool LaTeXFont::read(Lexer & lex)
{
- switchdefault_ = 0;
- osfdefault_ = 0;
- moreopts_ = 0;
- osffontonly_ = 0;
+ switchdefault_ = false;
+ osfdefault_ = false;
+ moreopts_ = false;
+ osffontonly_ = false;
if (!lex.next()) {
lex.printError("No name given for LaTeX font: `$$Token'.");
diff --git a/src/Language.cpp b/src/Language.cpp
index 9b17628..4f625b5 100644
--- a/src/Language.cpp
+++ b/src/Language.cpp
@@ -278,9 +278,9 @@ bool Language::readLanguage(Lexer & lex)
bool Language::read(Lexer & lex)
{
- encoding_ = 0;
- internal_enc_ = 0;
- rightToLeft_ = 0;
+ encoding_ = nullptr;
+ internal_enc_ = false;
+ rightToLeft_ = false;
if (!lex.next()) {
lex.printError("No name given for language: `$$Token'.");
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 8ea7eec..242f644 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -1087,7 +1087,7 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
runparams.local_font = &basefont;
}
- if (fontswitch_inset && !closeLanguage && fontswitch_inset) {
+ if (fontswitch_inset && !closeLanguage) {
// The directionality has been switched at inset.
// Force markup inside.
runparams.local_font = &basefont;
diff --git a/src/Text.h b/src/Text.h
index b5160a9..8209b09 100644
--- a/src/Text.h
+++ b/src/Text.h
@@ -94,11 +94,11 @@ public:
};
/// Increase or decrease the nesting depth of the selected paragraph(s)
/// FIXME: replace Cursor with DocIterator.
- void changeDepth(Cursor & cur, DEPTH_CHANGE type);
+ void changeDepth(Cursor const & cur, DEPTH_CHANGE type);
/// Returns whether something would be changed by changeDepth
/// FIXME: replace Cursor with DocIterator.
- bool changeDepthAllowed(Cursor & cur, DEPTH_CHANGE type) const;
+ bool changeDepthAllowed(Cursor const & cur, DEPTH_CHANGE type) const;
/// Set font over selection paragraphs and rebreak.
/// FIXME: replace Cursor with DocIterator.
@@ -356,7 +356,7 @@ private:
/// handle the case where bibitems were deleted
bool handleBibitems(Cursor & cur);
/// are we in a list item (description etc.)?
- bool inDescriptionItem(Cursor & cur) const;
+ bool inDescriptionItem(Cursor const & cur) const;
///
void charInserted(Cursor & cur);
/// set 'number' font property
diff --git a/src/Text2.cpp b/src/Text2.cpp
index ed4b133..a78700c 100644
--- a/src/Text2.cpp
+++ b/src/Text2.cpp
@@ -222,7 +222,7 @@ static bool changeDepthAllowed(Text::DEPTH_CHANGE type,
}
-bool Text::changeDepthAllowed(Cursor & cur, DEPTH_CHANGE type) const
+bool Text::changeDepthAllowed(Cursor const & cur, DEPTH_CHANGE type) const
{
LBUFERR(this == cur.text());
// this happens when selecting several cells in tabular (bug 2630)
@@ -242,7 +242,7 @@ bool Text::changeDepthAllowed(Cursor & cur, DEPTH_CHANGE type) const
}
-void Text::changeDepth(Cursor & cur, DEPTH_CHANGE type)
+void Text::changeDepth(Cursor const & cur, DEPTH_CHANGE type)
{
LBUFERR(this == cur.text());
pit_type const beg = cur.selBegin().pit();
diff --git a/src/Text3.cpp b/src/Text3.cpp
index 05d6bc2..6631d49 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -3683,9 +3683,9 @@ void Text::pasteString(Cursor & cur, docstring const & clip,
// FIXME: an item inset would make things much easier.
-bool Text::inDescriptionItem(Cursor & cur) const
+bool Text::inDescriptionItem(Cursor const & cur) const
{
- Paragraph & par = cur.paragraph();
+ Paragraph const & par = cur.paragraph();
pos_type const pos = cur.pos();
pos_type const body_pos = par.beginOfBody();
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index 5cc4586..8e9a157 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -221,7 +221,7 @@ void TextMetrics::newParMetricsUp()
}
-bool TextMetrics::metrics(MetricsInfo & mi, Dimension & dim, int min_width,
+bool TextMetrics::metrics(MetricsInfo const & mi, Dimension & dim, int min_width,
bool const expand_on_multipars)
{
LBUFERR(mi.base.textwidth > 0);
@@ -676,7 +676,7 @@ void TextMetrics::setRowAlignment(Row & row, int width) const
}
// are there any hfills in the row?
- ParagraphMetrics & pm = par_metrics_[row.pit()];
+ ParagraphMetrics const & pm = par_metrics_[row.pit()];
int nh = numberOfHfills(row, pm, par.beginOfBody());
int hfill = 0;
int hfill_rem = 0;
diff --git a/src/TextMetrics.h b/src/TextMetrics.h
index 6484967..20e0dfb 100644
--- a/src/TextMetrics.h
+++ b/src/TextMetrics.h
@@ -71,7 +71,7 @@ public:
void newParMetricsUp();
/// compute text metrics.
- bool metrics(MetricsInfo & mi, Dimension & dim, int min_width = 0,
+ bool metrics(MetricsInfo const & mi, Dimension & dim, int min_width = 0,
bool const expand_on_multipars = true);
/// The "nodraw" drawing stage for one single paragraph: set the
diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp
index f1e6c2d..500d5e3 100644
--- a/src/TocBackend.cpp
+++ b/src/TocBackend.cpp
@@ -180,7 +180,7 @@ bool TocBackend::updateItem(DocIterator const & dit_in)
//
// FIXME: This is supposed to accomplish the same as the body of
// InsetText::iterateForToc(), probably
- Paragraph & par = toc_item->dit().paragraph();
+ Paragraph const & par = toc_item->dit().paragraph();
for (auto const & table : par.insetList())
if (InsetArgument const * arg = table.inset->asInsetArgument()) {
tocstring = par.labelString();
diff --git a/src/Trans.cpp b/src/Trans.cpp
index b73b884..679866d 100644
--- a/src/Trans.cpp
+++ b/src/Trans.cpp
@@ -200,9 +200,7 @@ void Trans::addDeadkey(tex_accent accent, docstring const & keys)
int Trans::load(Lexer & lex)
{
- bool error = false;
-
- while (lex.isOK() && !error) {
+ while (lex.isOK()) {
switch (lex.lex()) {
case KMOD:
{
diff --git a/src/frontends/qt/FindAndReplace.cpp b/src/frontends/qt/FindAndReplace.cpp
index 5605b00..271ce9b 100644
--- a/src/frontends/qt/FindAndReplace.cpp
+++ b/src/frontends/qt/FindAndReplace.cpp
@@ -108,7 +108,7 @@ bool FindAndReplaceWidget::eventFilter(QObject * obj, QEvent * event)
// with shift we (temporarily) change search/replace direction
bool const searchback = searchbackCB->isChecked();
if (e->modifiers() == Qt::ShiftModifier && !searchback)
- searchbackCB->setChecked(!searchback);
+ searchbackCB->setChecked(true);
if (obj == find_work_area_)
on_findNextPB_clicked();
diff --git a/src/frontends/qt/GuiBibtex.cpp b/src/frontends/qt/GuiBibtex.cpp
index 897224c..c0c33a5 100644
--- a/src/frontends/qt/GuiBibtex.cpp
+++ b/src/frontends/qt/GuiBibtex.cpp
@@ -269,7 +269,7 @@ void GuiBibtex::clearSelection()
}
-void GuiBibtex::setSelectedBibs(QStringList const sl)
+void GuiBibtex::setSelectedBibs(QStringList const & sl)
{
selected_model_.clear();
QStringList headers;
diff --git a/src/frontends/qt/GuiBibtex.h b/src/frontends/qt/GuiBibtex.h
index 192628c..cb17499 100644
--- a/src/frontends/qt/GuiBibtex.h
+++ b/src/frontends/qt/GuiBibtex.h
@@ -75,7 +75,7 @@ private:
/// Clear selected keys
void clearSelection();
/// Set selected keys
- void setSelectedBibs(QStringList const);
+ void setSelectedBibs(QStringList const &);
/// prepares a call to GuiCitation::searchKeys when we
/// are ready to search the Bib entries
void findText(QString const & text);
diff --git a/src/frontends/qt/GuiBox.cpp b/src/frontends/qt/GuiBox.cpp
index 5b504dd..298009d 100644
--- a/src/frontends/qt/GuiBox.cpp
+++ b/src/frontends/qt/GuiBox.cpp
@@ -286,8 +286,8 @@ void GuiBox::on_pagebreakCB_stateChanged()
{
bool pbreak = (pagebreakCB->checkState() == Qt::Checked);
if (pbreak)
- widthCB->setChecked(!pbreak);
- if (!pbreak) {
+ widthCB->setChecked(false);
+ else {
on_typeCO_activated(typeCO->currentIndex());
return;
}
diff --git a/src/frontends/qt/GuiCitation.cpp b/src/frontends/qt/GuiCitation.cpp
index 7a554e7..16b958b 100644
--- a/src/frontends/qt/GuiCitation.cpp
+++ b/src/frontends/qt/GuiCitation.cpp
@@ -654,7 +654,7 @@ void GuiCitation::clearSelection()
}
-void GuiCitation::setSelectedKeys(QStringList const sl)
+void GuiCitation::setSelectedKeys(QStringList const & sl)
{
selected_model_.clear();
selected_model_.setColumnCount(3);
diff --git a/src/frontends/qt/GuiCitation.h b/src/frontends/qt/GuiCitation.h
index 51a53b1..a4784b2 100644
--- a/src/frontends/qt/GuiCitation.h
+++ b/src/frontends/qt/GuiCitation.h
@@ -117,7 +117,7 @@ private:
void clearSelection();
/// Set selected keys
- void setSelectedKeys(QStringList const);
+ void setSelectedKeys(QStringList const &);
/// Get selected keys
QStringList selectedKeys();
/// Set pre texts of qualified lists
diff --git a/src/frontends/qt/GuiLyXFiles.cpp b/src/frontends/qt/GuiLyXFiles.cpp
index c9dbf90..8269c4d 100644
--- a/src/frontends/qt/GuiLyXFiles.cpp
+++ b/src/frontends/qt/GuiLyXFiles.cpp
@@ -569,7 +569,7 @@ void GuiLyXFiles::passParams(string const & data)
}
-void GuiLyXFiles::selectItem(QString const item)
+void GuiLyXFiles::selectItem(QString const & item)
{
/* Using an intermediary variable flags is needed up to at least
* Qt 5.5 because of a subtle namespace issue. See:
diff --git a/src/frontends/qt/GuiLyXFiles.h b/src/frontends/qt/GuiLyXFiles.h
index e86678b..4d762fc 100644
--- a/src/frontends/qt/GuiLyXFiles.h
+++ b/src/frontends/qt/GuiLyXFiles.h
@@ -35,7 +35,7 @@ public:
/// A way to pass params to the dialog directly
void passParams(std::string const & data);
/// A way to pass params to the dialog directly
- void selectItem(QString const item);
+ void selectItem(QString const & item);
Q_SIGNALS:
void fileSelected(QString const file);
diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp
index c3b59bb..5f9e2d3 100644
--- a/src/lyxfind.cpp
+++ b/src/lyxfind.cpp
@@ -357,11 +357,10 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
bool whole, bool forward, bool findnext)
{
Cursor & cur = bv->cursor();
- bool found = false;
if (!cur.selection()) {
// no selection, non-empty search string: find it
if (!searchstr.empty()) {
- found = findOne(bv, searchstr, case_sens, whole, forward, true, findnext);
+ bool found = findOne(bv, searchstr, case_sens, whole, forward, true, findnext);
return make_pair(found, 0);
}
// empty search string
@@ -390,7 +389,7 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
// no selection or current selection is not search word:
// just find the search word
if (!have_selection || !match) {
- found = findOne(bv, searchstr, case_sens, whole, forward, true, findnext);
+ bool found = findOne(bv, searchstr, case_sens, whole, forward, true, findnext);
return make_pair(found, 0);
}
diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp
index 7e6ea6b..3d759bc 100644
--- a/src/mathed/MathStream.cpp
+++ b/src/mathed/MathStream.cpp
@@ -129,7 +129,7 @@ WriteStream::WriteStream(otexrowstream & os, bool fragile, bool latex,
OutputType output, Encoding const * encoding)
: os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
output_(output), pendingspace_(false), pendingbrace_(false),
- textmode_(false), locked_(0), ascii_(0), canbreakline_(true),
+ textmode_(false), locked_(false), ascii_(false), canbreakline_(true),
mathsout_(false), ulemcmd_(NONE), line_(0), encoding_(encoding),
row_entry_(TexRow::row_none), mathclass_(false)
{}
diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index 12f58aa..fefa62f 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -1668,7 +1668,7 @@ void latexParagraphs(Buffer const & buf,
|| par->params().leftIndent() == nextpar->params().leftIndent())
&& !runparams.for_search && cpar.size() > 0
&& cpar.isDeleted(0, cpar.size()) && !bparams.output_changes) {
- if (!bparams.output_changes && !cpar.parEndChange().deleted())
+ if (!cpar.parEndChange().deleted())
os << '\n' << '\n';
continue;
}
diff --git a/src/support/ForkedCalls.cpp b/src/support/ForkedCalls.cpp
index eb07314..7718a74 100644
--- a/src/support/ForkedCalls.cpp
+++ b/src/support/ForkedCalls.cpp
@@ -448,7 +448,7 @@ ForkedCall::sigPtr add(string const & process);
static queue<Process> callQueue_;
/// flag whether queue is running
-static bool running_ = 0;
+static bool running_ = false;
///
void startCaller();
diff --git a/src/support/debug.cpp b/src/support/debug.cpp
index 8bcd2e8..ada2577 100644
--- a/src/support/debug.cpp
+++ b/src/support/debug.cpp
@@ -134,7 +134,7 @@ Debug::Type Debug::value(string const & val)
break;
}
if (st == string::npos)
- break;
+ break;
v.erase(0, st + 1);
}
return l;
diff --git a/src/support/docstring.cpp b/src/support/docstring.cpp
index 0c5d3e6..550f528 100644
--- a/src/support/docstring.cpp
+++ b/src/support/docstring.cpp
@@ -344,8 +344,7 @@ protected:
const int c = wctob(i);
if (c == EOF)
break;
- else
- M_narrow[i] = static_cast<char>(c);
+ M_narrow[i] = static_cast<char>(c);
}
if (i == 128)
M_narrow_ok = true;
diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp
index 151d78c..8d48c8e 100644
--- a/src/support/filetools.cpp
+++ b/src/support/filetools.cpp
@@ -497,8 +497,7 @@ void removeTempFile(FileName const & fn)
return;
string const abs = fn.absFileName();
- if (tmp_names_.find(abs) != tmp_names_.end())
- tmp_names_.erase(abs);
+ tmp_names_.erase(abs);
fn.removeFile();
}
diff --git a/src/support/unicode.cpp b/src/support/unicode.cpp
index 5ea21aa..d84d81a 100644
--- a/src/support/unicode.cpp
+++ b/src/support/unicode.cpp
@@ -252,8 +252,8 @@ IconvProcessor & getProc(map<string, IconvProcessor> & processors,
if (it == processors.end()) {
IconvProcessor p(fromcode, tocode);
return processors.insert(make_pair(encoding, move(p))).first->second;
- } else
- return it->second;
+ }
+ return it->second;
}
} // namespace
diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index cf01fdd..b8cf686 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -2764,7 +2764,6 @@ void Preamble::parse(Parser & p, string const & forceclass,
// paper sizes
// some size options are known by the document class, other sizes
// are handled by the \geometry command of the geometry package
- string paper;
vector<string> class_psizes = getVectorFromString(tc.opt_pagesize(), "|");
string const psize_format = tc.pagesizeformat();
for (auto const & psize : class_psizes) {
diff --git a/src/tex2lyx/tex2lyx.h b/src/tex2lyx/tex2lyx.h
index 2b1eaf9..8ce7295 100644
--- a/src/tex2lyx/tex2lyx.h
+++ b/src/tex2lyx/tex2lyx.h
@@ -48,7 +48,7 @@ extern std::string rgbcolor2code(std::string const & name);
std::string translate_len(std::string const &);
void parse_text(Parser & p, std::ostream & os, unsigned flags, bool outer,
- Context & context, std::string const & rdelim = std::string());
+ Context & context, std::string const & rdelim = "");
void check_comment_bib(std::ostream & os, Context & context);
void fix_child_filename(std::string & name);
@@ -67,8 +67,8 @@ std::string find_file(std::string const & name, std::string const & path,
*/
void parse_text_in_inset(Parser & p, std::ostream & os, unsigned flags,
bool outer, Context const & context,
- InsetLayout const * layout = 0,
- std::string const & rdelim = std::string());
+ InsetLayout const * layout = nullptr,
+ std::string const & rdelim = "");
/// Guess document language from \p p if CJK is used.
/// \p lang is used for all non-CJK contents.
More information about the lyx-cvs
mailing list