Commit 20627471 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Fixed out-of-bounds when originalSource was not explicitly supplied.

Task-number: QTCREATORBUG-3613
parent 13cc7432
......@@ -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.
......
......@@ -75,6 +75,8 @@ protected:
Scope *switchScope(Scope *scope);
QString matchingLine(const Token &tk) const;
void reportResult(unsigned tokenIndex, const Name *name, Scope *scope = 0);
void reportResult(unsigned tokenIndex, const Identifier *id, Scope *scope = 0);
void reportResult(unsigned tokenIndex, const QList<LookupItem> &candidates);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment