cor3ntin created this revision. Herald added a subscriber: hiraditya. Herald added a project: All. cor3ntin requested review of this revision. Herald added projects: clang, LLVM. Herald added subscribers: llvm-commits, cfe-commits.
The length of valid codepoints was incorrectly calculated which was not caught before because the absence of tests for the valid codepoints scenario. Repository: rG LLVM Github Monorepo 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: 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; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits