diff options
| author | Erik Verbruggen <[email protected]> | 2011-01-27 14:51:01 +0100 |
|---|---|---|
| committer | Erik Verbruggen <[email protected]> | 2011-01-27 14:51:01 +0100 |
| commit | 206274715869a56d7406b66956651d97f9f07516 (patch) | |
| tree | 4786e6314ef5440e555026eb3abc93c874ea8dba /src/libs/cplusplus/FindUsages.cpp | |
| parent | 13cc74321e46b9992e77f4493bae307060f5eb38 (diff) | |
Fixed out-of-bounds when originalSource was not explicitly supplied.
Task-number: QTCREATORBUG-3613
Diffstat (limited to 'src/libs/cplusplus/FindUsages.cpp')
| -rw-r--r-- | src/libs/cplusplus/FindUsages.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/libs/cplusplus/FindUsages.cpp b/src/libs/cplusplus/FindUsages.cpp index f0b14d1ad63..4f3bb3fdf71 100644 --- a/src/libs/cplusplus/FindUsages.cpp +++ b/src/libs/cplusplus/FindUsages.cpp @@ -134,6 +134,27 @@ void FindUsages::reportResult(unsigned tokenIndex, const QList<LookupItem> &cand reportResult(tokenIndex); } +QString FindUsages::matchingLine(const Token &tk) const +{ + const char *beg = _source.constData(); + const char *cp = beg + tk.offset; + for (; cp != beg - 1; --cp) { + if (*cp == '\n') + break; + } + + ++cp; + + const char *lineEnd = cp + 1; + for (; *lineEnd; ++lineEnd) { + if (*lineEnd == '\n') + break; + } + + const QString matchingLine = QString::fromUtf8(cp, lineEnd - cp); + return matchingLine; +} + void FindUsages::reportResult(unsigned tokenIndex) { const Token &tk = tokenAt(tokenIndex); @@ -146,7 +167,12 @@ void FindUsages::reportResult(unsigned tokenIndex) unsigned line, col; getTokenStartPosition(tokenIndex, &line, &col); - const QString lineText = QString::fromUtf8(_originalSource.split('\n').at(line - 1)); + QString lineText; + QList<QByteArray> lines = _originalSource.split('\n'); + if (lines.size() < ((int) line - 1)) + lineText = matchingLine(tk); + else + lineText = QString::fromUtf8(lines.at(line - 1)); if (col) --col; // adjust the column position. |
