aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/3rdparty/cplusplus/TranslationUnit.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2024-01-19 08:10:38 -0800
committerThiago Macieira <thiago.macieira@intel.com>2024-01-23 20:36:57 +0000
commit7b04bdf491bc661fd508d33aa1d4e650c50e9811 (patch)
tree59d7d47ce38d45587bacab7bf960cd5d7480199e /src/libs/3rdparty/cplusplus/TranslationUnit.cpp
parent1a29f87440c996eb969c57028471c1aba04a5309 (diff)
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>
Diffstat (limited to 'src/libs/3rdparty/cplusplus/TranslationUnit.cpp')
-rw-r--r--src/libs/3rdparty/cplusplus/TranslationUnit.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/libs/3rdparty/cplusplus/TranslationUnit.cpp b/src/libs/3rdparty/cplusplus/TranslationUnit.cpp
index 848f61285c..e680ee2660 100644
--- a/src/libs/3rdparty/cplusplus/TranslationUnit.cpp
+++ b/src/libs/3rdparty/cplusplus/TranslationUnit.cpp
@@ -27,6 +27,7 @@
#include "Literals.h"
#include "DiagnosticClient.h"
+#include "cppassert.h"
#include <utils/textutils.h>
#include <stack>
@@ -87,6 +88,7 @@ int TranslationUnit::sourceLength() const
void TranslationUnit::setSource(const char *source, int size)
{
+ CPP_CHECK(source);
_firstSourceChar = source;
_lastSourceChar = source + size;
}