summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2020-03-30 18:13:43 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2020-04-01 13:39:43 +0000
commit11cd79adca8b136a7c06dd127635564022382219 (patch)
tree668549f004f2770a37b71849cb20a5429ca3cd9d
parentf75e54160d293d46ce9c0394c80bedf02d0ff461 (diff)
downloadqt-creator-11cd79adca8b136a7c06dd127635564022382219.tar.gz
ProWriter: Fix removeVarValues() function
This function wrongly assumed that there is always an empty line between variable assignments. For instance, When renaming a header file in a project file where HEADERS follows right after SOURCES, the function would erroneously claim that it removed the header file from the SOURCES segment, so follow-up code added the name name there instead of to HEADERS. Fixes: QTCREATORBUG-23720 Change-Id: I55288b22fe16fa0593b277d8808ab5d64ba90549 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r--src/shared/proparser/prowriter.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/shared/proparser/prowriter.cpp b/src/shared/proparser/prowriter.cpp
index 52d49751f2..e3fcc5f600 100644
--- a/src/shared/proparser/prowriter.cpp
+++ b/src/shared/proparser/prowriter.cpp
@@ -471,12 +471,17 @@ QList<int> ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
// This code expects proVars to be sorted by the variables' appearance in the file.
int delta = 1;
- for (const VarLocation &loc : qAsConst(varLocations)) {
+ for (int varIndex = 0; varIndex < varLocations.count(); ++varIndex) {
+ const VarLocation &loc = varLocations[varIndex];
bool first = true;
int lineNo = loc.second - delta;
typedef QPair<int, int> ContPos;
QList<ContPos> contPos;
- while (lineNo < lines->count()) {
+ const auto nextSegmentStart = [varIndex, lines, &delta, &varLocations] {
+ return varIndex == varLocations.count() - 1
+ ? lines->count() : varLocations[varIndex + 1].second - delta;
+ };
+ while (lineNo < nextSegmentStart()) {
QString &line = (*lines)[lineNo];
int lineLen = line.length();
bool killed = false;