Author: Sergei Barannikov Date: 2023-02-16T15:19:24+03:00 New Revision: 574e417460cdfebb8157fbe61b6a015e44856f64
URL: https://github.com/llvm/llvm-project/commit/574e417460cdfebb8157fbe61b6a015e44856f64 DIFF: https://github.com/llvm/llvm-project/commit/574e417460cdfebb8157fbe61b6a015e44856f64.diff LOG: [clang] Fix a bug that allowed some overflowing octal escape sequences Reviewed By: cor3ntin Differential Revision: https://reviews.llvm.org/D144100 Added: Modified: clang/lib/Lex/LiteralSupport.cpp clang/test/Lexer/char-escapes-delimited.c Removed: ################################################################################ diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp index 421a853360430..38b68bde4b516 100644 --- a/clang/lib/Lex/LiteralSupport.cpp +++ b/clang/lib/Lex/LiteralSupport.cpp @@ -263,7 +263,8 @@ static unsigned ProcessCharEscape(const char *ThisTokBegin, ThisTokBuf++; continue; } - if (ResultChar & 0x020000000) + // Check if one of the top three bits is set before shifting them out. + if (ResultChar & 0xE0000000) Overflow = true; ResultChar <<= 3; diff --git a/clang/test/Lexer/char-escapes-delimited.c b/clang/test/Lexer/char-escapes-delimited.c index 8e7094bc2ca5d..3b1deffe936db 100644 --- a/clang/test/Lexer/char-escapes-delimited.c +++ b/clang/test/Lexer/char-escapes-delimited.c @@ -58,6 +58,8 @@ void octal(void) { #if __WCHAR_MAX__ > 0xFFFF unsigned d = L'\o{37777777777}'; // ext-warning {{extension}} cxx2b-warning {{C++2b}} unsigned e = L'\o{40000000000}'; // expected-error {{octal escape sequence out of range}} + unsigned f = L'\o{100000000000}'; // expected-error {{octal escape sequence out of range}} + unsigned g = L'\o{200000000000}'; // expected-error {{octal escape sequence out of range}} #else unsigned d = L'\o{177777}'; // ext-warning {{extension}} cxx2b-warning {{C++2b}} unsigned e = L'\o{200000}'; // expected-error {{octal escape sequence out of range}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits