diff options
author | Dmitry Vasilyev <dvassiliev@accesssoftek.com> | 2025-09-12 20:56:21 +0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-09-12 20:56:21 +0400 |
commit | a848008e1996f8934dee0a297975ac0e6b4200ec (patch) | |
tree | c0cdaec2fbfeefe2908980639bb87dd5ea696eb0 /lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp | |
parent | ba9d1c41c41d568a798e0a8c38a89d294647c28d (diff) | |
download | llvm-a848008e1996f8934dee0a297975ac0e6b4200ec.zip llvm-a848008e1996f8934dee0a297975ac0e6b4200ec.tar.gz llvm-a848008e1996f8934dee0a297975ac0e6b4200ec.tar.bz2 |
[lldb] Fixed UB in CPlusPlusLanguage plug-in (#158304)
C++11 allows the use of Universal Character Names (UCNs) in identifiers,
including function names.
According to the spec the behavior of std::isalpha(ch) and
std::isalnum(ch) is undefined if the argument's value is neither
representable as unsigned char nor equal to EOF. To use these functions
safely with plain chars (or signed chars), the argument should first be
converted to unsigned char.
Diffstat (limited to 'lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp')
-rw-r--r-- | lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp index 277de8f..1f7b8d4 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp @@ -190,14 +190,16 @@ static bool IsTrivialBasename(const llvm::StringRef &basename) { if (basename.size() <= idx) return false; // Empty string or "~" - if (!std::isalpha(basename[idx]) && basename[idx] != '_') + if (!std::isalpha(static_cast<unsigned char>(basename[idx])) && + basename[idx] != '_') return false; // First character (after removing the possible '~'') isn't in // [A-Za-z_] // Read all characters matching [A-Za-z_0-9] ++idx; while (idx < basename.size()) { - if (!std::isalnum(basename[idx]) && basename[idx] != '_') + if (!std::isalnum(static_cast<unsigned char>(basename[idx])) && + basename[idx] != '_') break; ++idx; } |