aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/scanner
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2018-05-28 16:03:16 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2018-05-30 13:29:10 +0000
commit24b624b09388e4ea27de38e058b3d3d59e67bb30 (patch)
treee484e163c93bb7259a1440bd9865bdad68850656 /src/plugins/scanner
parentbb86d55c9e8614e6cf5819f0300d12d021402195 (diff)
C++ scanner: Properly handle UTF-8 byte order mark
Includes in the first line of a source file starting with a byte order mark would not get detected, resulting in failure to recompile after a header file change. Skip over the BOM before passing the data to the lexer. Task-number: QBS-1348 Done-with: Ola Røer Thorsen <ola@silentwings.no> Change-Id: I894a5b1667e49be5f8ce9b5cc66e4e796fd073f1 Reviewed-by: Ola Røer Thorsen <ola@silentwings.no> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/plugins/scanner')
-rw-r--r--src/plugins/scanner/cpp/cppscanner.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/plugins/scanner/cpp/cppscanner.cpp b/src/plugins/scanner/cpp/cppscanner.cpp
index 7e5cbe146..1d7fb7c84 100644
--- a/src/plugins/scanner/cpp/cppscanner.cpp
+++ b/src/plugins/scanner/cpp/cppscanner.cpp
@@ -248,6 +248,16 @@ static void *openScanner(const unsigned short *filePath, const char *fileTags, i
return nullptr;
opaque->fileContent = reinterpret_cast<char *>(vmap);
+
+ // Check for UTF-8 Byte Order Mark (BOM). Skip if found.
+ if (mapl >= 3
+ && opaque->fileContent[0] == char(0xef)
+ && opaque->fileContent[1] == char(0xbb)
+ && opaque->fileContent[2] == char(0xbf)) {
+ opaque->fileContent += 3;
+ mapl -= 3;
+ }
+
CPlusPlus::Lexer lex(opaque->fileContent, opaque->fileContent + mapl);
scanCppFile(opaque.get(), lex, flags & ScanForFileTagsFlag, flags & ScanForDependenciesFlag);
return opaque.release();