diff options
author | Tatyana Krasnukha <tatyana@synopsys.com> | 2018-09-26 18:50:19 +0000 |
---|---|---|
committer | Tatyana Krasnukha <tatyana@synopsys.com> | 2018-09-26 18:50:19 +0000 |
commit | 8fe53c490a567d3e9337b974057a239477dbe685 (patch) | |
tree | 66605824e7ac9bdd8691bc9fef8415a5f62ab62d /lldb/source/Interpreter/Options.cpp | |
parent | bcdfcbcb1d8694c0f0630e3c326cbda437b24c14 (diff) | |
download | bcm5719-llvm-8fe53c490a567d3e9337b974057a239477dbe685.tar.gz bcm5719-llvm-8fe53c490a567d3e9337b974057a239477dbe685.zip |
Replace "nullptr-terminated" C-arrays of OptionValueEnumeration with safer llvm::ArrayRef
Differential Revision: https://reviews.llvm.org/D49017
llvm-svn: 343130
Diffstat (limited to 'lldb/source/Interpreter/Options.cpp')
-rw-r--r-- | lldb/source/Interpreter/Options.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/lldb/source/Interpreter/Options.cpp b/lldb/source/Interpreter/Options.cpp index c9567e91f6b..bdea5b4180e 100644 --- a/lldb/source/Interpreter/Options.cpp +++ b/lldb/source/Interpreter/Options.cpp @@ -601,15 +601,17 @@ void Options::GenerateOptionUsage(Stream &strm, CommandObject *cmd, if (opt_defs[i].usage_text) OutputFormattedUsageText(strm, opt_defs[i], screen_width); - if (opt_defs[i].enum_values != nullptr) { + if (!opt_defs[i].enum_values.empty()) { strm.Indent(); strm.Printf("Values: "); - for (int k = 0; opt_defs[i].enum_values[k].string_value != nullptr; - k++) { - if (k == 0) - strm.Printf("%s", opt_defs[i].enum_values[k].string_value); + bool is_first = true; + for (const auto &enum_value : opt_defs[i].enum_values) { + if (is_first) { + strm.Printf("%s", enum_value.string_value); + is_first = false; + } else - strm.Printf(" | %s", opt_defs[i].enum_values[k].string_value); + strm.Printf(" | %s", enum_value.string_value); } strm.EOL(); } @@ -770,17 +772,18 @@ bool Options::HandleOptionArgumentCompletion( // See if this is an enumeration type option, and if so complete it here: - OptionEnumValueElement *enum_values = opt_defs[opt_defs_index].enum_values; - if (enum_values != nullptr) { + const auto &enum_values = opt_defs[opt_defs_index].enum_values; + if (!enum_values.empty()) { bool return_value = false; std::string match_string( request.GetParsedLine().GetArgumentAtIndex(opt_arg_pos), request.GetParsedLine().GetArgumentAtIndex(opt_arg_pos) + request.GetCursorCharPosition()); - for (int i = 0; enum_values[i].string_value != nullptr; i++) { - if (strstr(enum_values[i].string_value, match_string.c_str()) == - enum_values[i].string_value) { - request.AddCompletion(enum_values[i].string_value); + + for (const auto &enum_value : enum_values) { + if (strstr(enum_value.string_value, match_string.c_str()) == + enum_value.string_value) { + request.AddCompletion(enum_value.string_value); return_value = true; } } |