summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTopi Reinio <topi.reinio@qt.io>2023-01-05 12:07:31 +0000
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-02-28 10:57:14 +0000
commit54a3efd2ee4be4ca114d3bdb78a413cdcb8c6339 (patch)
tree40097c13ea5605e0c939b7db2dd979b72c337539
parent070d3e3e4cb84e2a9e0aa015b74ab27758af464c (diff)
qdoc: Clean up code related to processing of \include'd lines
* Use qsizetype instead of int. * Remove unnecessary variable 'startLine'. * Replace a while loop with a for loop. * Replace nested conditional statements with (A && B). * Fix a corner case where a lone snippet tag at the last line of included file caused out-of-bounds access of the line buffer. Change-Id: I0b1009cf122681bcf700b67040a3d0ca19e82378 Reviewed-by: Paul Wicking <paul.wicking@qt.io> (cherry picked from commit f5a950df40295248b5da5aec261b2eb309033e25) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qdoc/docparser.cpp34
1 files changed, 14 insertions, 20 deletions
diff --git a/src/qdoc/docparser.cpp b/src/qdoc/docparser.cpp
index dc7b4a61f..0ca616577 100644
--- a/src/qdoc/docparser.cpp
+++ b/src/qdoc/docparser.cpp
@@ -1348,38 +1348,32 @@ void DocParser::include(const QString &fileName, const QString &identifier, cons
m_openedInputs.push(m_position + includedContent.size());
} else {
QStringList lineBuffer = includedContent.split(QLatin1Char('\n'));
- int i = 0;
- int startLine = -1;
+ qsizetype bufLen{lineBuffer.size()};
+ qsizetype i;
QStringView trimmedLine;
- while (i < lineBuffer.size()) {
+ for (i = 0; i < bufLen; ++i) {
trimmedLine = QStringView{lineBuffer[i]}.trimmed();
- if (trimmedLine.startsWith(QLatin1String("//!"))) {
- if (trimmedLine.contains(identifier)) {
- startLine = i + 1;
- break;
- }
- }
- ++i;
+ if (trimmedLine.startsWith(QLatin1String("//!")) &&
+ trimmedLine.contains(identifier))
+ break;
}
- if (startLine < 0) {
+ if (i < bufLen - 1) {
+ ++i;
+ } else {
location().warning(
QStringLiteral("Cannot find '%1' in '%2'").arg(identifier, filePath));
return;
}
QString result;
- i = startLine;
do {
trimmedLine = QStringView{lineBuffer[i]}.trimmed();
- if (trimmedLine.startsWith(QLatin1String("//!"))) {
- if (i < lineBuffer.size()) {
- if (trimmedLine.contains(identifier)) {
- break;
- }
- }
- } else
+ if (trimmedLine.startsWith(QLatin1String("//!")) &&
+ trimmedLine.contains(identifier))
+ break;
+ else
result += lineBuffer[i] + QLatin1Char('\n');
++i;
- } while (i < lineBuffer.size());
+ } while (i < bufLen);
expandArgumentsInString(result, parameters);
if (result.isEmpty()) {