forked from qt-creator/qt-creator
CPlusPlus: deal with QByteArray::(c)begin() return nullptr
You should either use begin() and end(), or data() and size(), and either way you shouldn't dereference the first iterator if the size is zero. Roberto's parser in 3rdparty/cplusplus assumes you've passed at least one character (I'm guessing the null terminator) and does pointer manipulation there: void Lexer::setSource(const char *firstChar, const char *lastChar) { _firstChar = firstChar; _lastChar = lastChar; _currentChar = _firstChar - 1; _currentCharUtf16 = ~0; _tokenStart = _currentChar; _yychar = '\n'; } Note the _firstChar - 1 math is technically UB if firstChar is the actual first character of any buffer allocation or string. Fixes: QTCREATORBUG-30044 Change-Id: I76ffba14ece04f24b43efffd17abcb8102497813 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
#include "Literals.h"
|
#include "Literals.h"
|
||||||
#include "DiagnosticClient.h"
|
#include "DiagnosticClient.h"
|
||||||
|
|
||||||
|
#include "cppassert.h"
|
||||||
#include <utils/textutils.h>
|
#include <utils/textutils.h>
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
@@ -87,6 +88,7 @@ int TranslationUnit::sourceLength() const
|
|||||||
|
|
||||||
void TranslationUnit::setSource(const char *source, int size)
|
void TranslationUnit::setSource(const char *source, int size)
|
||||||
{
|
{
|
||||||
|
CPP_CHECK(source);
|
||||||
_firstSourceChar = source;
|
_firstSourceChar = source;
|
||||||
_lastSourceChar = source + size;
|
_lastSourceChar = source + size;
|
||||||
}
|
}
|
||||||
|
@@ -527,7 +527,7 @@ Document::Ptr Document::create(const FilePath &filePath)
|
|||||||
void Document::setUtf8Source(const QByteArray &source)
|
void Document::setUtf8Source(const QByteArray &source)
|
||||||
{
|
{
|
||||||
_source = source;
|
_source = source;
|
||||||
_translationUnit->setSource(_source.constBegin(), _source.size());
|
_translationUnit->setSource(_source.constData(), _source.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
LanguageFeatures Document::languageFeatures() const
|
LanguageFeatures Document::languageFeatures() const
|
||||||
|
Reference in New Issue
Block a user