Here are next 5 patches. Yuriy
From bdf2a935f79f465e75bafdedc3e50a4a513e24ca Mon Sep 17 00:00:00 2001 From: Yuriy Skalko <yuriy.ska...@gmail.com> Date: Thu, 26 Nov 2020 00:17:29 +0200 Subject: [PATCH 1/5] Use to_string function
--- src/client/client.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index dd69fe20f5..0a80107009 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -93,14 +93,6 @@ Messages const & getMessages(string const &) namespace support { -string itoa(unsigned int i) -{ - char buf[20]; - sprintf(buf, "%d", i); - return buf; -} - - /// Returns the absolute pathnames of all lyx local sockets in /// file system encoding. /// Parts stolen from lyx::support::DirList(). @@ -469,7 +461,7 @@ int h(vector<docstring> const &) docstring clientName = - from_ascii(itoa(::getppid()) + ">" + itoa(::getpid())); + from_ascii(to_string(::getppid()) + ">" + to_string(::getpid())); int n(vector<docstring> const & arg) { -- 2.28.0.windows.1
From 2af4904d7a947be564f74f005c2b8ff47859ca47 Mon Sep 17 00:00:00 2001 From: Yuriy Skalko <yuriy.ska...@gmail.com> Date: Thu, 26 Nov 2020 01:11:07 +0200 Subject: [PATCH 2/5] Constify --- src/Counters.cpp | 2 +- src/Counters.h | 2 +- src/Server.cpp | 2 +- src/Server.h | 4 ++-- src/graphics/PreviewImage.cpp | 4 ++-- src/lyxfind.cpp | 28 ++++++++++++++-------------- src/tex2lyx/Parser.cpp | 2 +- src/tex2lyx/Parser.h | 2 +- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Counters.cpp b/src/Counters.cpp index 8477d5283a..139dc9bcd7 100644 --- a/src/Counters.cpp +++ b/src/Counters.cpp @@ -413,7 +413,7 @@ bool Counters::remove(docstring const & cnt) } -void Counters::copy(Counters const & from, Counters & to, docstring const & match) +void Counters::copy(Counters const & from, Counters & to, docstring const & match) const { for (auto const & ctr : counterList_) { if (ctr.first.find(match) != string::npos || match == "") { diff --git a/src/Counters.h b/src/Counters.h index 4708f5a331..e6554a284f 100644 --- a/src/Counters.h +++ b/src/Counters.h @@ -163,7 +163,7 @@ public: /// Copy counters whose name matches match from the &from to /// the &to array of counters. Empty string matches all. void copy(Counters const & from, Counters & to, - docstring const & match = docstring()); + docstring const & match = docstring()) const; /** returns the expanded string representation of counter \c * c. The \c lang code is used to translate the string. */ diff --git a/src/Server.cpp b/src/Server.cpp index fe503926de..79340492c6 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -1003,7 +1003,7 @@ struct Sleep : QThread } // namespace -bool LyXComm::loadFilesInOtherInstance() +bool LyXComm::loadFilesInOtherInstance() const { int pipefd; FileName const pipe(inPipeName()); diff --git a/src/Server.h b/src/Server.h index 9257704b43..b277284ace 100644 --- a/src/Server.h +++ b/src/Server.h @@ -120,7 +120,7 @@ private: void closeConnection(); /// Load files in another running instance of LyX - bool loadFilesInOtherInstance(); + bool loadFilesInOtherInstance() const; #ifndef _WIN32 /// start a pipe @@ -212,7 +212,7 @@ public: /// void notifyClient(std::string const &); /// - bool deferredLoadingToOtherInstance() { return pipes_.deferredLoading(); } + bool deferredLoadingToOtherInstance() const { return pipes_.deferredLoading(); } /// whilst crashing etc. void emergencyCleanup() { pipes_.emergencyCleanup(); } diff --git a/src/graphics/PreviewImage.cpp b/src/graphics/PreviewImage.cpp index b80bf9415b..062dd6e7bc 100644 --- a/src/graphics/PreviewImage.cpp +++ b/src/graphics/PreviewImage.cpp @@ -35,7 +35,7 @@ public: /// ~Impl(); /// - Image const * image(); + Image const * image() const; /// void statusChanged(); @@ -125,7 +125,7 @@ PreviewImage::Impl::~Impl() } -Image const * PreviewImage::Impl::image() +Image const * PreviewImage::Impl::image() const { if (iloader_.status() == WaitingToLoad) iloader_.startLoading(); diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index c438052d2e..fc7b0b737a 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -1101,20 +1101,20 @@ public: int depts[MAXOPENED]; int closes[MAXOPENED]; int actualdeptindex; - int previousNotIgnored(int); - int nextNotIgnored(int); + int previousNotIgnored(int) const; + int nextNotIgnored(int) const; void handleOpenP(int i); void handleCloseP(int i, bool closingAllowed); void resetOpenedP(int openPos); void addIntervall(int upper); void addIntervall(int low, int upper); /* if explicit */ void removeAccents(); - void setForDefaultLang(KeyInfo const & defLang); + void setForDefaultLang(KeyInfo const & defLang) const; int findclosing(int start, int end, char up, char down, int repeat); void handleParentheses(int lastpos, bool closingAllowed); bool hasTitle; int langcount; // Number of disabled language specs up to current position in actual interval - int isOpeningPar(int pos); + int isOpeningPar(int pos) const; string titleValue; void output(ostringstream &os, int lastpos); // string show(int lastpos); @@ -1122,7 +1122,7 @@ public: vector<Border> Intervall::borders = vector<Border>(30); -int Intervall::isOpeningPar(int pos) +int Intervall::isOpeningPar(int pos) const { if ((pos < 0) || (size_t(pos) >= par.size())) return 0; @@ -1137,7 +1137,7 @@ int Intervall::isOpeningPar(int pos) return 1; } -void Intervall::setForDefaultLang(KeyInfo const & defLang) +void Intervall::setForDefaultLang(KeyInfo const & defLang) const { // Enable the use of first token again if (ignoreidx >= 0) { @@ -1418,7 +1418,7 @@ void Intervall::resetOpenedP(int openPos) closes[1] = -1; } -int Intervall::previousNotIgnored(int start) +int Intervall::previousNotIgnored(int start) const { int idx = 0; /* int intervalls */ for (idx = ignoreidx; idx >= 0; --idx) { @@ -1430,7 +1430,7 @@ int Intervall::previousNotIgnored(int start) return start; } -int Intervall::nextNotIgnored(int start) +int Intervall::nextNotIgnored(int start) const { int idx = 0; /* int intervalls */ for (idx = 0; idx <= ignoreidx; idx++) { @@ -1504,7 +1504,7 @@ class LatexInfo { else return false; }; - int find(int start, KeyInfo::KeyType keytype) { + int find(int start, KeyInfo::KeyType keytype) const { if (start < 0) return -1; int tmpIdx = start; @@ -1526,7 +1526,7 @@ class LatexInfo { else return entries_[keyinfo]; }; - void setForDefaultLang(KeyInfo &defLang) {interval_.setForDefaultLang(defLang);}; + void setForDefaultLang(KeyInfo const & defLang) {interval_.setForDefaultLang(defLang);}; void addIntervall(int low, int up) { interval_.addIntervall(low, up); }; }; @@ -1577,14 +1577,14 @@ class MathInfo { m.mathSize = end - start; entries_.push_back(m); } - bool empty() { return entries_.empty(); }; - size_t getEndPos() { + bool empty() const { return entries_.empty(); }; + size_t getEndPos() const { if (entries_.empty() || (actualIdx_ >= entries_.size())) { return 0; } return entries_[actualIdx_].mathEnd; } - size_t getStartPos() { + size_t getStartPos() const { if (entries_.empty() || (actualIdx_ >= entries_.size())) { return 100000; /* definitely enough? */ } @@ -1594,7 +1594,7 @@ class MathInfo { actualIdx_ = 0; return getStartPos(); } - size_t getSize() { + size_t getSize() const { if (entries_.empty() || (actualIdx_ >= entries_.size())) { return size_t(0); } diff --git a/src/tex2lyx/Parser.cpp b/src/tex2lyx/Parser.cpp index ee25db246d..67e0323c96 100644 --- a/src/tex2lyx/Parser.cpp +++ b/src/tex2lyx/Parser.cpp @@ -877,7 +877,7 @@ void Parser::dump() const } -void Parser::error(string const & msg) +void Parser::error(string const & msg) const { cerr << "Line ~" << lineno_ << ": parse error: " << msg << endl; dump(); diff --git a/src/tex2lyx/Parser.h b/src/tex2lyx/Parser.h index 9f174c8a0b..d28036710e 100644 --- a/src/tex2lyx/Parser.h +++ b/src/tex2lyx/Parser.h @@ -310,7 +310,7 @@ public: /// std::string verbatimOption(); /// - void error(std::string const & msg); + void error(std::string const & msg) const; /// The previous token. Token const prev_token() const; /// The current token. -- 2.28.0.windows.1
From ad0511626d386c85611aefda7a5bfa00365314ea Mon Sep 17 00:00:00 2001 From: Yuriy Skalko <yuriy.ska...@gmail.com> Date: Thu, 26 Nov 2020 22:10:45 +0200 Subject: [PATCH 3/5] Use iround function, amend c0ce79452f --- src/Row.cpp | 5 +++-- src/Spacing.cpp | 5 +++-- src/graphics/PreviewImage.cpp | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Row.cpp b/src/Row.cpp index 9ab7f11037..02923d1dd1 100644 --- a/src/Row.cpp +++ b/src/Row.cpp @@ -26,6 +26,7 @@ #include "support/debug.h" #include "support/lassert.h" #include "support/lstrings.h" +#include "support/lyxlib.h" #include <algorithm> #include <ostream> @@ -297,7 +298,7 @@ int Row::left_x() const x += cit->full_width(); ++cit; } - return int(x + 0.5); + return support::iround(x); } @@ -313,7 +314,7 @@ int Row::right_x() const else break; } - return int(x + 0.5); + return support::iround(x); } diff --git a/src/Spacing.cpp b/src/Spacing.cpp index 9ac8345ab4..ce645398f8 100644 --- a/src/Spacing.cpp +++ b/src/Spacing.cpp @@ -12,8 +12,9 @@ #include <config.h> #include "Spacing.h" -#include "support/lstrings.h" #include "support/convert.h" +#include "support/lstrings.h" +#include "support/lyxlib.h" #include <ostream> @@ -55,7 +56,7 @@ void Spacing::set(Spacing::Space sp, string const & val) { space = sp; if (sp == Other) { - switch (int(convert<double>(val) * 1000 + 0.5)) { + switch (support::iround(convert<double>(val) * 1000)) { case 1000: space = Single; break; diff --git a/src/graphics/PreviewImage.cpp b/src/graphics/PreviewImage.cpp index 062dd6e7bc..b31af6fbd9 100644 --- a/src/graphics/PreviewImage.cpp +++ b/src/graphics/PreviewImage.cpp @@ -19,6 +19,7 @@ #include "PreviewLoader.h" #include "support/FileName.h" +#include "support/lyxlib.h" using namespace std; @@ -85,7 +86,7 @@ Dimension PreviewImage::dim() const if (!image) return dim; - dim.asc = int(pimpl_->ascent_frac_ * double(image->height()) + 0.5); + dim.asc = support::iround(pimpl_->ascent_frac_ * double(image->height())); dim.des = image->height() - dim.asc; dim.wid = image->width(); return dim; -- 2.28.0.windows.1
From b3326101f4b96b27a97bed550c3ec6ef2e600ab0 Mon Sep 17 00:00:00 2001 From: Yuriy Skalko <yuriy.ska...@gmail.com> Date: Thu, 26 Nov 2020 22:14:43 +0200 Subject: [PATCH 4/5] Replace ;; --- src/insets/InsetNewpage.cpp | 2 +- src/mathed/InsetMathGrid.cpp | 2 +- src/mathed/InsetMathMacroTemplate.cpp | 2 +- src/mathed/InsetMathSpecialChar.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/insets/InsetNewpage.cpp b/src/insets/InsetNewpage.cpp index 9f343ae2e2..897a946887 100644 --- a/src/insets/InsetNewpage.cpp +++ b/src/insets/InsetNewpage.cpp @@ -162,7 +162,7 @@ void InsetNewpage::draw(PainterInfo & pi, int x, int y) const pi.pain.lines(xp, yp, 2, ColorName()); //mid-rule - xp[0] = xp[1] = int(x + wid * 0.5);; + xp[0] = xp[1] = int(x + wid * 0.5); yp[0] = int(y - 0.875 * asc * 0.75); yp[1] = int(y - 0.125 * asc * 0.75); pi.pain.lines(xp, yp, 2, ColorName()); diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index ba3bda6d95..7158df2e43 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -483,7 +483,7 @@ void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const colinfo_[ncols()].width = 0; // compute horizontal offsets - colinfo_[0].offset = border() + colinfo_[0].lines * vlinesep();; + colinfo_[0].offset = border() + colinfo_[0].lines * vlinesep(); for (col_type col = 1; col <= ncols(); ++col) { colinfo_[col].offset = colinfo_[col - 1].offset + diff --git a/src/mathed/InsetMathMacroTemplate.cpp b/src/mathed/InsetMathMacroTemplate.cpp index 1152936ee2..7f43586513 100644 --- a/src/mathed/InsetMathMacroTemplate.cpp +++ b/src/mathed/InsetMathMacroTemplate.cpp @@ -573,7 +573,7 @@ void InsetMathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const if (macro) macro->unlock(); - dim.wid += leftOffset(mi.base.bv) + rightOffset(mi.base.bv);; + dim.wid += leftOffset(mi.base.bv) + rightOffset(mi.base.bv); dim.des += bottomOffset(mi.base.bv); dim.asc += topOffset(mi.base.bv); } diff --git a/src/mathed/InsetMathSpecialChar.cpp b/src/mathed/InsetMathSpecialChar.cpp index 701bcc8686..f2a9a737f3 100644 --- a/src/mathed/InsetMathSpecialChar.cpp +++ b/src/mathed/InsetMathSpecialChar.cpp @@ -56,7 +56,7 @@ Inset * InsetMathSpecialChar::clone() const void InsetMathSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const { if (mi.base.fontname == "mathnormal") { - Changer dummy = mi.base.font.changeShape(UP_SHAPE);; + Changer dummy = mi.base.font.changeShape(UP_SHAPE); dim = theFontMetrics(mi.base.font).dimension(char_); } else { frontend::FontMetrics const & fm = theFontMetrics(mi.base.font); -- 2.28.0.windows.1
From c7b38c8be83047afa92d88ac8e1750073e997863 Mon Sep 17 00:00:00 2001 From: Yuriy Skalko <yuriy.ska...@gmail.com> Date: Thu, 26 Nov 2020 23:01:18 +0200 Subject: [PATCH 5/5] Fix signed integer overflow on x = 0, detected by GCC sanitizer --- src/support/lstrings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp index f0e79b88b3..9aac66a754 100644 --- a/src/support/lstrings.cpp +++ b/src/support/lstrings.cpp @@ -1446,8 +1446,8 @@ std::string formatFPNumber(double x) os << std::fixed; // Prevent outputs of 23.4200000000000017 but output small numbers // with at least 6 significant digits. - double const logarithm = log10(fabs(x)); - os << std::setprecision(max(6 - iround(logarithm), 0)) << x; + int const precision = (x == 0.0) ? 0 : max(6 - iround(log10(fabs(x))), 0); + os << std::setprecision(precision) << x; string result = os.str(); if (result.find('.') != string::npos) { result = rtrim(result, "0"); -- 2.28.0.windows.1
-- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel