[PATCH] D129223: [Clang] Fix invalid utf-8 detection

Corentin Jabot via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 6 13:20:13 PDT 2022


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbf45e27a676d: [Clang] Fix invalid utf-8 detection (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129223/new/

https://reviews.llvm.org/D129223

Files:
  clang/test/Lexer/comment-invalid-utf8.c
  llvm/lib/Support/ConvertUTF.cpp


Index: llvm/lib/Support/ConvertUTF.cpp
===================================================================
--- llvm/lib/Support/ConvertUTF.cpp
+++ llvm/lib/Support/ConvertUTF.cpp
@@ -423,7 +423,7 @@
  */
 unsigned getUTF8SequenceSize(const UTF8 *source, const UTF8 *sourceEnd) {
   int length = trailingBytesForUTF8[*source] + 1;
-  return (length > sourceEnd - source && isLegalUTF8(source, length)) ? length
+  return (length < sourceEnd - source && isLegalUTF8(source, length)) ? length
                                                                       : 0;
 }
 
Index: clang/test/Lexer/comment-invalid-utf8.c
===================================================================
--- clang/test/Lexer/comment-invalid-utf8.c
+++ clang/test/Lexer/comment-invalid-utf8.c
@@ -25,3 +25,14 @@
 // abcd
 // €abcd
 // expected-warning at -1 {{invalid UTF-8 in comment}}
+
+
+//§ § § 😀 你好 ©
+
+/*§ § § 😀 你好 ©*/
+
+/*
+§ § § 😀 你好 ©
+*/
+
+/* § § § 😀 你好 © */


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129223.442674.patch
Type: text/x-patch
Size: 1068 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220706/49230b8a/attachment-0001.bin>


More information about the cfe-commits mailing list