diff --git a/lldb/include/lldb/Utility/OptionDefinition.h b/lldb/include/lldb/Utility/OptionDefinition.h --- a/lldb/include/lldb/Utility/OptionDefinition.h +++ b/lldb/include/lldb/Utility/OptionDefinition.h @@ -12,6 +12,7 @@ #include "lldb/lldb-enumerations.h" #include "lldb/lldb-private-types.h" #include "llvm/ADT/StringExtras.h" +#include #include namespace lldb_private { @@ -47,7 +48,9 @@ /// Whether this has a short option character. bool HasShortOption() const { // See the short_option documentation for more. - return llvm::isPrint(short_option); + // Must not have any bits set outside of unsigned char range + return !(short_option & ~((1 << CHAR_BIT) - 1)) && + llvm::isPrint(short_option); } }; } // namespace lldb_private diff --git a/lldb/test/API/commands/help/TestHelp.py b/lldb/test/API/commands/help/TestHelp.py --- a/lldb/test/API/commands/help/TestHelp.py +++ b/lldb/test/API/commands/help/TestHelp.py @@ -57,6 +57,11 @@ self.runCmd("help unsigned-integer") @no_debug_info_test + def test_help_memory_read_should_not_crash_lldb(self): + """Command 'help memory read' should not crash lldb.""" + self.runCmd("help memory read", check=False) + + @no_debug_info_test def test_help_should_not_hang_emacsshell(self): """Command 'settings set term-width 0' should not hang the help command.""" self.expect(