Compare commits

...

2 Commits

Author SHA1 Message Date
Jean-Marc Lasgouttes
bc624cc780 Do not pass a vector by value to getArgInset
Instead of passing the vector by value so that stuff can be added to
it in the function, add required elements of arguments to a second vector.

While we are at it, simplify the code a bit by using a range-for and
auto keyword.

Spotted by Coverity scan
2024-10-01 13:06:37 +02:00
Jean-Marc Lasgouttes
54b6846941 Pass parameters as const reference
Spotted by Coverity scan.
2024-10-01 11:12:14 +02:00
3 changed files with 18 additions and 21 deletions

View File

@ -2326,7 +2326,7 @@ QRectF GuiApplication::baseInputItemRectangle()
} }
void GuiApplication::setBaseInputItemRectangle(QRectF rect) void GuiApplication::setBaseInputItemRectangle(QRectF const & rect)
{ {
d->item_rect_base_ = rect; d->item_rect_base_ = rect;
} }
@ -2338,7 +2338,7 @@ QTransform GuiApplication::baseInputItemTransform()
} }
void GuiApplication::setBaseInputItemTransform(QTransform trans) void GuiApplication::setBaseInputItemTransform(QTransform const & trans)
{ {
d->item_trans_base_ = trans; d->item_trans_base_ = trans;
} }

View File

@ -192,11 +192,11 @@ public:
/// input item rectangle of the base view /// input item rectangle of the base view
QRectF baseInputItemRectangle(); QRectF baseInputItemRectangle();
/// set input item rectangle of the base view /// set input item rectangle of the base view
void setBaseInputItemRectangle(QRectF rect); void setBaseInputItemRectangle(QRectF const & rect);
/// input item transform of the base view /// input item transform of the base view
QTransform baseInputItemTransform(); QTransform baseInputItemTransform();
/// set input item transform of the base view /// set input item transform of the base view
void setBaseInputItemTransform(QTransform trans); void setBaseInputItemTransform(QTransform const & trans);
/// \name Methods to process FuncRequests /// \name Methods to process FuncRequests
//@{ //@{

View File

@ -501,13 +501,10 @@ void TeXEnvironment(Buffer const & buf, Text const & text,
} }
// FIXME: pass the \c required vector by reference and add the stuff
// from \c latexargs to a different vector. This avoids a copy and
// (more importantly?) a coverity defect.
void getArgInsets(otexstream & os, OutputParams const & runparams, void getArgInsets(otexstream & os, OutputParams const & runparams,
Layout::LaTeXArgMap const & latexargs, Layout::LaTeXArgMap const & latexargs,
map<size_t, lyx::InsetArgument const *> const & ilist, map<size_t, lyx::InsetArgument const *> const & ilist,
vector<string> required, string const & prefix) vector<string> const & required, string const & prefix)
{ {
size_t const argnr = latexargs.size(); size_t const argnr = latexargs.size();
if (argnr == 0) if (argnr == 0)
@ -515,24 +512,24 @@ void getArgInsets(otexstream & os, OutputParams const & runparams,
// Default and preset args are always output, so if they require // Default and preset args are always output, so if they require
// other arguments, consider this. // other arguments, consider this.
vector<string> required_args;
for (auto const & larg : latexargs) { for (auto const & larg : latexargs) {
Layout::latexarg const & arg = larg.second; Layout::latexarg const & arg = larg.second;
if ((!arg.presetarg.empty() || !arg.defaultarg.empty()) && !arg.required.empty()) { if ((!arg.presetarg.empty() || !arg.defaultarg.empty()) && !arg.required.empty()) {
vector<string> req = getVectorFromString(arg.required); vector<string> const req = getVectorFromString(arg.required);
required.insert(required.end(), req.begin(), req.end()); required_args.insert(required_args.end(), req.begin(), req.end());
} }
} }
for (size_t i = 1; i <= argnr; ++i) { for (size_t i = 1; i <= argnr; ++i) {
map<size_t, InsetArgument const *>::const_iterator lit = ilist.find(i); auto const lit = ilist.find(i);
bool inserted = false; bool inserted = false;
if (lit != ilist.end()) { if (lit != ilist.end()) {
InsetArgument const * ins = lit->second; InsetArgument const * ins = lit->second;
if (ins) { if (ins) {
Layout::LaTeXArgMap::const_iterator const lait = auto const lait = latexargs.find(ins->name());
latexargs.find(ins->name());
if (lait != latexargs.end()) { if (lait != latexargs.end()) {
Layout::latexarg arg = lait->second; Layout::latexarg const arg = lait->second;
docstring ldelim; docstring ldelim;
docstring rdelim; docstring rdelim;
if (!arg.nodelims) { if (!arg.nodelims) {
@ -553,12 +550,10 @@ void getArgInsets(otexstream & os, OutputParams const & runparams,
} }
} }
if (!inserted) { if (!inserted) {
Layout::LaTeXArgMap::const_iterator lait = latexargs.begin(); for (auto const & la_p : latexargs) {
Layout::LaTeXArgMap::const_iterator const laend = latexargs.end();
for (; lait != laend; ++lait) {
string const name = prefix + convert<string>(i); string const name = prefix + convert<string>(i);
if ((*lait).first == name) { if (la_p.first == name) {
Layout::latexarg arg = (*lait).second; Layout::latexarg const arg = la_p.second;
docstring preset = arg.presetarg; docstring preset = arg.presetarg;
if (!arg.defaultarg.empty()) { if (!arg.defaultarg.empty()) {
if (!preset.empty()) if (!preset.empty())
@ -578,7 +573,9 @@ void getArgInsets(otexstream & os, OutputParams const & runparams,
from_ascii("]") : arg.rdelim; from_ascii("]") : arg.rdelim;
os << ldelim << preset << rdelim; os << ldelim << preset << rdelim;
} else if (find(required.begin(), required.end(), } else if (find(required.begin(), required.end(),
(*lait).first) != required.end()) { la_p.first) != required.end()
|| find(required_args.begin(), required_args.end(),
la_p.first) != required_args.end()) {
docstring ldelim = arg.ldelim.empty() ? docstring ldelim = arg.ldelim.empty() ?
from_ascii("[") : arg.ldelim; from_ascii("[") : arg.ldelim;
docstring rdelim = arg.rdelim.empty() ? docstring rdelim = arg.rdelim.empty() ?