Refactoring based on cppcheck suggestions

This commit is contained in:
Yuriy Skalko 2020-10-01 13:34:15 +03:00 committed by Jean-Marc Lasgouttes
parent a43d8501a2
commit 715b8cda54
34 changed files with 49 additions and 59 deletions

View File

@ -53,7 +53,6 @@ docstring Author::nameAndEmail() const
{ {
if (email().empty()) if (email().empty())
return name(); return name();
else
return bformat(_("%1$s[[name]] (%2$s[[email]])"), name(), email()); return bformat(_("%1$s[[name]] (%2$s[[email]])"), name(), email());
} }

View File

@ -1549,7 +1549,6 @@ bool Buffer::save() const
// time stamp is invalidated by copying/moving // time stamp is invalidated by copying/moving
saveCheckSum(); saveCheckSum();
markClean(); markClean();
if (d->file_format != LYX_FORMAT)
// the file associated with this buffer is now in the current format // the file associated with this buffer is now in the current format
d->file_format = LYX_FORMAT; d->file_format = LYX_FORMAT;
return true; return true;

View File

@ -232,7 +232,7 @@ public:
/// ///
Impl(Compare const & compare) Impl(Compare const & compare)
: abort_(false), n_(0), m_(0), offset_reverse_diagonal_(0), : 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), old_buf_(nullptr), new_buf_(nullptr), dest_buf_(nullptr),
dest_pars_(nullptr), recursion_level_(0), nested_inset_level_(0), D_(0) 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); static_cast<InsetText &>(dest_buffer->inset()), el);
finished(pimpl_->abort_); finished(pimpl_->abort_);
return;
} }

View File

@ -737,7 +737,7 @@ void region(CursorSlice const & i1, CursorSlice const & i2,
Inset::row_type & r1, Inset::row_type & r2, Inset::row_type & r1, Inset::row_type & r2,
Inset::col_type & c1, Inset::col_type & c2) Inset::col_type & c1, Inset::col_type & c2)
{ {
Inset & p = i1.inset(); Inset const & p = i1.inset();
c1 = p.col(i1.idx()); c1 = p.col(i1.idx());
c2 = p.col(i2.idx()); c2 = p.col(i2.idx());
if (c1 > c2) if (c1 > c2)
@ -1079,7 +1079,7 @@ void copySelectionToStack()
} }
void copySelectionToTemp(Cursor & cur) void copySelectionToTemp(Cursor const & cur)
{ {
copySelectionToStack(cur, tempCut); copySelectionToStack(cur, tempCut);
} }

View File

@ -66,7 +66,7 @@ void cutSelectionToTemp(Cursor & cur, bool realcut = true);
/// Push the current selection to the cut buffer and the system clipboard. /// Push the current selection to the cut buffer and the system clipboard.
void copySelection(Cursor const & cur); void copySelection(Cursor const & cur);
/// Like copySelection, but only put to temporary cut buffer /// 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); void copyInset(Cursor const & cur, Inset * inset, docstring const & plaintext);
/** /**

View File

@ -1648,7 +1648,6 @@ int LaTeX::scanIlgFile(TeXErrors & terr)
string prevtoken; string prevtoken;
while (getline(ifs, token)) { while (getline(ifs, token)) {
token = rtrim(token, "\r"); token = rtrim(token, "\r");
smatch sub;
if (prefixIs(token, "!! ")) if (prefixIs(token, "!! "))
prevtoken = token; prevtoken = token;
else if (!prevtoken.empty()) { else if (!prevtoken.empty()) {

View File

@ -522,10 +522,10 @@ bool LaTeXFont::readFont(Lexer & lex)
bool LaTeXFont::read(Lexer & lex) bool LaTeXFont::read(Lexer & lex)
{ {
switchdefault_ = 0; switchdefault_ = false;
osfdefault_ = 0; osfdefault_ = false;
moreopts_ = 0; moreopts_ = false;
osffontonly_ = 0; osffontonly_ = false;
if (!lex.next()) { if (!lex.next()) {
lex.printError("No name given for LaTeX font: `$$Token'."); lex.printError("No name given for LaTeX font: `$$Token'.");

View File

@ -278,9 +278,9 @@ bool Language::readLanguage(Lexer & lex)
bool Language::read(Lexer & lex) bool Language::read(Lexer & lex)
{ {
encoding_ = 0; encoding_ = nullptr;
internal_enc_ = 0; internal_enc_ = false;
rightToLeft_ = 0; rightToLeft_ = false;
if (!lex.next()) { if (!lex.next()) {
lex.printError("No name given for language: `$$Token'."); lex.printError("No name given for language: `$$Token'.");

View File

@ -1087,7 +1087,7 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
runparams.local_font = &basefont; runparams.local_font = &basefont;
} }
if (fontswitch_inset && !closeLanguage && fontswitch_inset) { if (fontswitch_inset && !closeLanguage) {
// The directionality has been switched at inset. // The directionality has been switched at inset.
// Force markup inside. // Force markup inside.
runparams.local_font = &basefont; runparams.local_font = &basefont;

View File

@ -94,11 +94,11 @@ public:
}; };
/// Increase or decrease the nesting depth of the selected paragraph(s) /// Increase or decrease the nesting depth of the selected paragraph(s)
/// FIXME: replace Cursor with DocIterator. /// 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 /// Returns whether something would be changed by changeDepth
/// FIXME: replace Cursor with DocIterator. /// 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. /// Set font over selection paragraphs and rebreak.
/// FIXME: replace Cursor with DocIterator. /// FIXME: replace Cursor with DocIterator.
@ -356,7 +356,7 @@ private:
/// handle the case where bibitems were deleted /// handle the case where bibitems were deleted
bool handleBibitems(Cursor & cur); bool handleBibitems(Cursor & cur);
/// are we in a list item (description etc.)? /// are we in a list item (description etc.)?
bool inDescriptionItem(Cursor & cur) const; bool inDescriptionItem(Cursor const & cur) const;
/// ///
void charInserted(Cursor & cur); void charInserted(Cursor & cur);
/// set 'number' font property /// set 'number' font property

View File

@ -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()); LBUFERR(this == cur.text());
// this happens when selecting several cells in tabular (bug 2630) // 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()); LBUFERR(this == cur.text());
pit_type const beg = cur.selBegin().pit(); pit_type const beg = cur.selBegin().pit();

View File

@ -3683,9 +3683,9 @@ void Text::pasteString(Cursor & cur, docstring const & clip,
// FIXME: an item inset would make things much easier. // 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 pos = cur.pos();
pos_type const body_pos = par.beginOfBody(); pos_type const body_pos = par.beginOfBody();

View File

@ -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) bool const expand_on_multipars)
{ {
LBUFERR(mi.base.textwidth > 0); LBUFERR(mi.base.textwidth > 0);
@ -676,7 +676,7 @@ void TextMetrics::setRowAlignment(Row & row, int width) const
} }
// are there any hfills in the row? // 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 nh = numberOfHfills(row, pm, par.beginOfBody());
int hfill = 0; int hfill = 0;
int hfill_rem = 0; int hfill_rem = 0;

View File

@ -71,7 +71,7 @@ public:
void newParMetricsUp(); void newParMetricsUp();
/// compute text metrics. /// 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); bool const expand_on_multipars = true);
/// The "nodraw" drawing stage for one single paragraph: set the /// The "nodraw" drawing stage for one single paragraph: set the

View File

@ -180,7 +180,7 @@ bool TocBackend::updateItem(DocIterator const & dit_in)
// //
// FIXME: This is supposed to accomplish the same as the body of // FIXME: This is supposed to accomplish the same as the body of
// InsetText::iterateForToc(), probably // InsetText::iterateForToc(), probably
Paragraph & par = toc_item->dit().paragraph(); Paragraph const & par = toc_item->dit().paragraph();
for (auto const & table : par.insetList()) for (auto const & table : par.insetList())
if (InsetArgument const * arg = table.inset->asInsetArgument()) { if (InsetArgument const * arg = table.inset->asInsetArgument()) {
tocstring = par.labelString(); tocstring = par.labelString();

View File

@ -200,9 +200,7 @@ void Trans::addDeadkey(tex_accent accent, docstring const & keys)
int Trans::load(Lexer & lex) int Trans::load(Lexer & lex)
{ {
bool error = false; while (lex.isOK()) {
while (lex.isOK() && !error) {
switch (lex.lex()) { switch (lex.lex()) {
case KMOD: case KMOD:
{ {

View File

@ -108,7 +108,7 @@ bool FindAndReplaceWidget::eventFilter(QObject * obj, QEvent * event)
// with shift we (temporarily) change search/replace direction // with shift we (temporarily) change search/replace direction
bool const searchback = searchbackCB->isChecked(); bool const searchback = searchbackCB->isChecked();
if (e->modifiers() == Qt::ShiftModifier && !searchback) if (e->modifiers() == Qt::ShiftModifier && !searchback)
searchbackCB->setChecked(!searchback); searchbackCB->setChecked(true);
if (obj == find_work_area_) if (obj == find_work_area_)
on_findNextPB_clicked(); on_findNextPB_clicked();

View File

@ -269,7 +269,7 @@ void GuiBibtex::clearSelection()
} }
void GuiBibtex::setSelectedBibs(QStringList const sl) void GuiBibtex::setSelectedBibs(QStringList const & sl)
{ {
selected_model_.clear(); selected_model_.clear();
QStringList headers; QStringList headers;

View File

@ -75,7 +75,7 @@ private:
/// Clear selected keys /// Clear selected keys
void clearSelection(); void clearSelection();
/// Set selected keys /// Set selected keys
void setSelectedBibs(QStringList const); void setSelectedBibs(QStringList const &);
/// prepares a call to GuiCitation::searchKeys when we /// prepares a call to GuiCitation::searchKeys when we
/// are ready to search the Bib entries /// are ready to search the Bib entries
void findText(QString const & text); void findText(QString const & text);

View File

@ -286,8 +286,8 @@ void GuiBox::on_pagebreakCB_stateChanged()
{ {
bool pbreak = (pagebreakCB->checkState() == Qt::Checked); bool pbreak = (pagebreakCB->checkState() == Qt::Checked);
if (pbreak) if (pbreak)
widthCB->setChecked(!pbreak); widthCB->setChecked(false);
if (!pbreak) { else {
on_typeCO_activated(typeCO->currentIndex()); on_typeCO_activated(typeCO->currentIndex());
return; return;
} }

View File

@ -654,7 +654,7 @@ void GuiCitation::clearSelection()
} }
void GuiCitation::setSelectedKeys(QStringList const sl) void GuiCitation::setSelectedKeys(QStringList const & sl)
{ {
selected_model_.clear(); selected_model_.clear();
selected_model_.setColumnCount(3); selected_model_.setColumnCount(3);

View File

@ -117,7 +117,7 @@ private:
void clearSelection(); void clearSelection();
/// Set selected keys /// Set selected keys
void setSelectedKeys(QStringList const); void setSelectedKeys(QStringList const &);
/// Get selected keys /// Get selected keys
QStringList selectedKeys(); QStringList selectedKeys();
/// Set pre texts of qualified lists /// Set pre texts of qualified lists

View File

@ -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 /* Using an intermediary variable flags is needed up to at least
* Qt 5.5 because of a subtle namespace issue. See: * Qt 5.5 because of a subtle namespace issue. See:

View File

@ -35,7 +35,7 @@ public:
/// A way to pass params to the dialog directly /// A way to pass params to the dialog directly
void passParams(std::string const & data); void passParams(std::string const & data);
/// A way to pass params to the dialog directly /// A way to pass params to the dialog directly
void selectItem(QString const item); void selectItem(QString const & item);
Q_SIGNALS: Q_SIGNALS:
void fileSelected(QString const file); void fileSelected(QString const file);

View File

@ -357,11 +357,10 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
bool whole, bool forward, bool findnext) bool whole, bool forward, bool findnext)
{ {
Cursor & cur = bv->cursor(); Cursor & cur = bv->cursor();
bool found = false;
if (!cur.selection()) { if (!cur.selection()) {
// no selection, non-empty search string: find it // no selection, non-empty search string: find it
if (!searchstr.empty()) { 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); return make_pair(found, 0);
} }
// empty search string // empty search string
@ -390,7 +389,7 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
// no selection or current selection is not search word: // no selection or current selection is not search word:
// just find the search word // just find the search word
if (!have_selection || !match) { 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); return make_pair(found, 0);
} }

View File

@ -129,7 +129,7 @@ WriteStream::WriteStream(otexrowstream & os, bool fragile, bool latex,
OutputType output, Encoding const * encoding) OutputType output, Encoding const * encoding)
: os_(os), fragile_(fragile), firstitem_(false), latex_(latex), : os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
output_(output), pendingspace_(false), pendingbrace_(false), 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), mathsout_(false), ulemcmd_(NONE), line_(0), encoding_(encoding),
row_entry_(TexRow::row_none), mathclass_(false) row_entry_(TexRow::row_none), mathclass_(false)
{} {}

View File

@ -1668,7 +1668,7 @@ void latexParagraphs(Buffer const & buf,
|| par->params().leftIndent() == nextpar->params().leftIndent()) || par->params().leftIndent() == nextpar->params().leftIndent())
&& !runparams.for_search && cpar.size() > 0 && !runparams.for_search && cpar.size() > 0
&& cpar.isDeleted(0, cpar.size()) && !bparams.output_changes) { && cpar.isDeleted(0, cpar.size()) && !bparams.output_changes) {
if (!bparams.output_changes && !cpar.parEndChange().deleted()) if (!cpar.parEndChange().deleted())
os << '\n' << '\n'; os << '\n' << '\n';
continue; continue;
} }

View File

@ -448,7 +448,7 @@ ForkedCall::sigPtr add(string const & process);
static queue<Process> callQueue_; static queue<Process> callQueue_;
/// flag whether queue is running /// flag whether queue is running
static bool running_ = 0; static bool running_ = false;
/// ///
void startCaller(); void startCaller();

View File

@ -344,7 +344,6 @@ protected:
const int c = wctob(i); const int c = wctob(i);
if (c == EOF) if (c == EOF)
break; break;
else
M_narrow[i] = static_cast<char>(c); M_narrow[i] = static_cast<char>(c);
} }
if (i == 128) if (i == 128)

View File

@ -497,7 +497,6 @@ void removeTempFile(FileName const & fn)
return; return;
string const abs = fn.absFileName(); string const abs = fn.absFileName();
if (tmp_names_.find(abs) != tmp_names_.end())
tmp_names_.erase(abs); tmp_names_.erase(abs);
fn.removeFile(); fn.removeFile();
} }

View File

@ -252,7 +252,7 @@ IconvProcessor & getProc(map<string, IconvProcessor> & processors,
if (it == processors.end()) { if (it == processors.end()) {
IconvProcessor p(fromcode, tocode); IconvProcessor p(fromcode, tocode);
return processors.insert(make_pair(encoding, move(p))).first->second; return processors.insert(make_pair(encoding, move(p))).first->second;
} else }
return it->second; return it->second;
} }

View File

@ -2764,7 +2764,6 @@ void Preamble::parse(Parser & p, string const & forceclass,
// paper sizes // paper sizes
// some size options are known by the document class, other sizes // some size options are known by the document class, other sizes
// are handled by the \geometry command of the geometry package // are handled by the \geometry command of the geometry package
string paper;
vector<string> class_psizes = getVectorFromString(tc.opt_pagesize(), "|"); vector<string> class_psizes = getVectorFromString(tc.opt_pagesize(), "|");
string const psize_format = tc.pagesizeformat(); string const psize_format = tc.pagesizeformat();
for (auto const & psize : class_psizes) { for (auto const & psize : class_psizes) {

View File

@ -48,7 +48,7 @@ extern std::string rgbcolor2code(std::string const & name);
std::string translate_len(std::string const &); std::string translate_len(std::string const &);
void parse_text(Parser & p, std::ostream & os, unsigned flags, bool outer, 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 check_comment_bib(std::ostream & os, Context & context);
void fix_child_filename(std::string & name); 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, void parse_text_in_inset(Parser & p, std::ostream & os, unsigned flags,
bool outer, Context const & context, bool outer, Context const & context,
InsetLayout const * layout = 0, InsetLayout const * layout = nullptr,
std::string const & rdelim = std::string()); std::string const & rdelim = "");
/// Guess document language from \p p if CJK is used. /// Guess document language from \p p if CJK is used.
/// \p lang is used for all non-CJK contents. /// \p lang is used for all non-CJK contents.