Hi,
Since I am not able to run or even understand a minted test, I'll like
some feedback about this (straightforward?) patch.
Does it make sense? It was spotted by Coverity Scan.
JMarc
From 2a97a951901cd5efaede2dca19b873d71910d31d Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Thu, 20 Feb 2025 00:06:24 +0100
Subject: [PATCH] Use a while() loop instead of fighting against for()
In a loop where elements may be removed from a vector, it is dangerous
and weird to decrease the counter so that it can be incremented by the
for() ++i statement later without change. I suspect that things can go wrong
when i == 0, and at least Coverity Scan agrees.
Use while() instead.
---
src/insets/InsetListings.cpp | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp
index 89b71e7e4d..2019c1a522 100644
--- a/src/insets/InsetListings.cpp
+++ b/src/insets/InsetListings.cpp
@@ -207,18 +207,19 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) const
if (use_minted && (isfloat || contains(param_string, "language="))) {
// Get float placement and/or language of the code,
// then remove the relative options.
- vector<string> opts =
- getVectorFromString(param_string, ",", false);
- for (size_t i = 0; i < opts.size(); ++i) {
+ vector<string> opts = getVectorFromString(param_string, ",", false);
+ size_t i = 0;
+ while (i < opts.size()) {
if (prefixIs(opts[i], "float")) {
if (prefixIs(opts[i], "float="))
float_placement = opts[i].substr(6);
- opts.erase(opts.begin() + int(i--));
+ opts.erase(opts.begin() + i);
}
else if (prefixIs(opts[i], "language=")) {
minted_language = opts[i].substr(9);
- opts.erase(opts.begin() + int(i--));
- }
+ opts.erase(opts.begin() + i);
+ } else
+ ++i;
}
param_string = getStringFromVector(opts, ",");
}
--
2.45.2
--
lyx-devel mailing list
lyx-devel@lists.lyx.org
https://lists.lyx.org/mailman/listinfo/lyx-devel