This revision was automatically updated to reflect the committed changes.
Closed by commit rG3a6ba3675177: [lldb] Convert misc. StringConvert uses 
(authored by mgorny).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D110447?vs=375024&id=375030#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110447/new/

https://reviews.llvm.org/D110447

Files:
  lldb/source/Interpreter/OptionValueArray.cpp
  lldb/source/Interpreter/OptionValueFileSpecList.cpp
  lldb/source/Interpreter/OptionValuePathMappings.cpp
  lldb/source/Interpreter/OptionValueSInt64.cpp
  lldb/source/Interpreter/OptionValueUInt64.cpp
  lldb/source/Interpreter/Property.cpp
  
lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  lldb/source/Symbol/SymbolContext.cpp
  lldb/source/Target/UnixSignals.cpp
  lldb/tools/lldb-server/lldb-gdbserver.cpp
  lldb/unittests/debugserver/RNBSocketTest.cpp

Index: lldb/unittests/debugserver/RNBSocketTest.cpp
===================================================================
--- lldb/unittests/debugserver/RNBSocketTest.cpp
+++ lldb/unittests/debugserver/RNBSocketTest.cpp
@@ -15,7 +15,6 @@
 #include "RNBDefs.h"
 #include "RNBSocket.h"
 #include "lldb/Host/Socket.h"
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Host/common/TCPSocket.h"
 #include "llvm/Testing/Support/Error.h"
 
Index: lldb/tools/lldb-server/lldb-gdbserver.cpp
===================================================================
--- lldb/tools/lldb-server/lldb-gdbserver.cpp
+++ lldb/tools/lldb-server/lldb-gdbserver.cpp
@@ -26,7 +26,6 @@
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/Pipe.h"
 #include "lldb/Host/Socket.h"
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Host/common/NativeProcessProtocol.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Utility/Status.h"
@@ -238,7 +237,8 @@
     if (colon_pos != std::string::npos) {
       connection_host = final_host_and_port.substr(0, colon_pos);
       connection_port = final_host_and_port.substr(colon_pos + 1);
-      connection_portno = StringConvert::ToUInt32(connection_port.c_str(), 0);
+      // FIXME: improve error handling
+      llvm::to_integer(connection_port, connection_portno);
     }
 
 
Index: lldb/source/Target/UnixSignals.cpp
===================================================================
--- lldb/source/Target/UnixSignals.cpp
+++ lldb/source/Target/UnixSignals.cpp
@@ -12,7 +12,6 @@
 #include "Plugins/Process/Utility/MipsLinuxSignals.h"
 #include "Plugins/Process/Utility/NetBSDSignals.h"
 #include "lldb/Host/HostInfo.h"
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Utility/ArchSpec.h"
 
 using namespace lldb_private;
@@ -156,9 +155,8 @@
       return pos->first;
   }
 
-  const int32_t signo =
-      StringConvert::ToSInt32(name, LLDB_INVALID_SIGNAL_NUMBER, 0);
-  if (signo != LLDB_INVALID_SIGNAL_NUMBER)
+  int32_t signo;
+  if (llvm::to_integer(name, signo))
     return signo;
   return LLDB_INVALID_SIGNAL_NUMBER;
 }
Index: lldb/source/Symbol/SymbolContext.cpp
===================================================================
--- lldb/source/Symbol/SymbolContext.cpp
+++ lldb/source/Symbol/SymbolContext.cpp
@@ -11,7 +11,6 @@
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Host/Host.h"
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Symbol/Block.h"
 #include "lldb/Symbol/CompileUnit.h"
 #include "lldb/Symbol/ObjectFile.h"
@@ -977,13 +976,11 @@
     m_type |= eFileSpecified;
     break;
   case eLineStartSpecified:
-    m_start_line = StringConvert::ToSInt32(spec_string, 0, 0, &return_value);
-    if (return_value)
+    if ((return_value = llvm::to_integer(spec_string, m_start_line)))
       m_type |= eLineStartSpecified;
     break;
   case eLineEndSpecified:
-    m_end_line = StringConvert::ToSInt32(spec_string, 0, 0, &return_value);
-    if (return_value)
+    if ((return_value = llvm::to_integer(spec_string, m_end_line)))
       m_type |= eLineEndSpecified;
     break;
   case eFunctionSpecified:
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -9,7 +9,6 @@
 #include "DWARFUnit.h"
 
 #include "lldb/Core/Module.h"
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Utility/LLDBAssert.h"
 #include "lldb/Utility/StreamString.h"
@@ -687,12 +686,10 @@
         llvm::SmallVector<llvm::StringRef, 4> matches;
         if (g_clang_version_regex.Execute(llvm::StringRef(producer_cstr),
                                           &matches)) {
-          m_producer_version_major =
-              StringConvert::ToUInt32(matches[1].str().c_str(), UINT32_MAX, 10);
-          m_producer_version_minor =
-              StringConvert::ToUInt32(matches[2].str().c_str(), UINT32_MAX, 10);
-          m_producer_version_update =
-              StringConvert::ToUInt32(matches[3].str().c_str(), UINT32_MAX, 10);
+          // FIXME: improve error handling
+          llvm::to_integer(matches[1], m_producer_version_major);
+          llvm::to_integer(matches[2], m_producer_version_minor);
+          llvm::to_integer(matches[3], m_producer_version_update);
         }
         m_producer = eProducerClang;
       } else if (strstr(producer_cstr, "GNU"))
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -1999,6 +1999,7 @@
   // Iterate through all of the thread dictionary key/value pairs from the
   // structured data dictionary
 
+  // FIXME: we're silently ignoring invalid data here
   thread_dict->ForEach([this, &tid, &expedited_register_map, &thread_name,
                         &signo, &reason, &description, &exc_type, &exc_data,
                         &thread_dispatch_qaddr, &queue_vars_valid,
@@ -2063,9 +2064,8 @@
         registers_dict->ForEach(
             [&expedited_register_map](ConstString key,
                                       StructuredData::Object *object) -> bool {
-              const uint32_t reg =
-                  StringConvert::ToUInt32(key.GetCString(), UINT32_MAX, 10);
-              if (reg != UINT32_MAX)
+              uint32_t reg;
+              if (llvm::to_integer(key.AsCString(), reg))
                 expedited_register_map[reg] =
                     std::string(object->GetStringValue());
               return true; // Keep iterating through all array items
@@ -4343,6 +4343,7 @@
         bool encoding_set = false;
         bool format_set = false;
 
+        // FIXME: we're silently ignoring invalid data here
         reg_node.ForEachAttribute([&target_info, &gdb_group, &gdb_type,
                                    &encoding_set, &format_set, &reg_info](
                                       const llvm::StringRef &name,
@@ -4350,21 +4351,16 @@
           if (name == "name") {
             reg_info.name.SetString(value);
           } else if (name == "bitsize") {
-            reg_info.byte_size =
-                StringConvert::ToUInt32(value.data(), 0, 0) / CHAR_BIT;
+            if (llvm::to_integer(value, reg_info.byte_size))
+              reg_info.byte_size /= CHAR_BIT;
           } else if (name == "type") {
             gdb_type = value.str();
           } else if (name == "group") {
             gdb_group = value.str();
           } else if (name == "regnum") {
-            const uint32_t regnum =
-                StringConvert::ToUInt32(value.data(), LLDB_INVALID_REGNUM, 0);
-            if (regnum != LLDB_INVALID_REGNUM) {
-              reg_info.regnum_remote = regnum;
-            }
+            llvm::to_integer(value, reg_info.regnum_remote);
           } else if (name == "offset") {
-            reg_info.byte_offset =
-                StringConvert::ToUInt32(value.data(), LLDB_INVALID_INDEX32, 0);
+            llvm::to_integer(value, reg_info.byte_offset);
           } else if (name == "altname") {
             reg_info.alt_name.SetString(value);
           } else if (name == "encoding") {
@@ -4388,18 +4384,16 @@
                       .Case("vector-uint128", eFormatVectorOfUInt128)
                       .Default(eFormatInvalid);
           } else if (name == "group_id") {
-            const uint32_t set_id =
-                StringConvert::ToUInt32(value.data(), UINT32_MAX, 0);
+            uint32_t set_id = UINT32_MAX;
+            llvm::to_integer(value, set_id);
             RegisterSetMap::const_iterator pos =
                 target_info.reg_set_map.find(set_id);
             if (pos != target_info.reg_set_map.end())
               reg_info.set_name = pos->second.name;
           } else if (name == "gcc_regnum" || name == "ehframe_regnum") {
-            reg_info.regnum_ehframe =
-                StringConvert::ToUInt32(value.data(), LLDB_INVALID_REGNUM, 0);
+            llvm::to_integer(value, reg_info.regnum_ehframe);
           } else if (name == "dwarf_regnum") {
-            reg_info.regnum_dwarf =
-                StringConvert::ToUInt32(value.data(), LLDB_INVALID_REGNUM, 0);
+            llvm::to_integer(value, reg_info.regnum_dwarf);
           } else if (name == "generic") {
             reg_info.regnum_generic = Args::StringToGenericRegister(value);
           } else if (name == "value_regnums") {
@@ -4510,9 +4504,9 @@
                 node.ForEachAttribute(
                     [&set_id, &set_info](const llvm::StringRef &name,
                                          const llvm::StringRef &value) -> bool {
+                      // FIXME: we're silently ignoring invalid data here
                       if (name == "id")
-                        set_id = StringConvert::ToUInt32(value.data(),
-                                                         UINT32_MAX, 0);
+                        llvm::to_integer(value, set_id);
                       if (name == "name")
                         set_info.name = ConstString(value);
                       return true; // Keep iterating through all attributes
@@ -4708,38 +4702,39 @@
 
     // main link map structure
     llvm::StringRef main_lm = root_element.GetAttributeValue("main-lm");
-    if (!main_lm.empty()) {
-      list.m_link_map =
-          StringConvert::ToUInt64(main_lm.data(), LLDB_INVALID_ADDRESS, 0);
-    }
+    // FIXME: we're silently ignoring invalid data here
+    if (!main_lm.empty())
+      llvm::to_integer(main_lm, list.m_link_map);
 
     root_element.ForEachChildElementWithName(
         "library", [log, &list](const XMLNode &library) -> bool {
 
           LoadedModuleInfoList::LoadedModuleInfo module;
 
+          // FIXME: we're silently ignoring invalid data here
           library.ForEachAttribute(
               [&module](const llvm::StringRef &name,
                         const llvm::StringRef &value) -> bool {
 
+                uint64_t uint_value = LLDB_INVALID_ADDRESS;
                 if (name == "name")
                   module.set_name(value.str());
                 else if (name == "lm") {
                   // the address of the link_map struct.
-                  module.set_link_map(StringConvert::ToUInt64(
-                      value.data(), LLDB_INVALID_ADDRESS, 0));
+                  llvm::to_integer(value, uint_value);
+                  module.set_link_map(uint_value);
                 } else if (name == "l_addr") {
                   // the displacement as read from the field 'l_addr' of the
                   // link_map struct.
-                  module.set_base(StringConvert::ToUInt64(
-                      value.data(), LLDB_INVALID_ADDRESS, 0));
+                  llvm::to_integer(value, uint_value);
+                  module.set_base(uint_value);
                   // base address is always a displacement, not an absolute
                   // value.
                   module.set_base_is_offset(true);
                 } else if (name == "l_ld") {
                   // the memory address of the libraries PT_DYNAMIC section.
-                  module.set_dynamic(StringConvert::ToUInt64(
-                      value.data(), LLDB_INVALID_ADDRESS, 0));
+                  llvm::to_integer(value, uint_value);
+                  module.set_dynamic(uint_value);
                 }
 
                 return true; // Keep iterating over all properties of "library"
@@ -4794,6 +4789,7 @@
       return llvm::createStringError(llvm::inconvertibleErrorCode(),
                                      "Error finding library-list xml element");
 
+    // FIXME: we're silently ignoring invalid data here
     root_element.ForEachChildElementWithName(
         "library", [log, &list](const XMLNode &library) -> bool {
           LoadedModuleInfoList::LoadedModuleInfo module;
@@ -4807,8 +4803,9 @@
           const XMLNode &section =
               library.FindFirstChildElementWithName("section");
           llvm::StringRef address = section.GetAttributeValue("address");
-          module.set_base(
-              StringConvert::ToUInt64(address.data(), LLDB_INVALID_ADDRESS, 0));
+          uint64_t address_value = LLDB_INVALID_ADDRESS;
+          llvm::to_integer(address, address_value);
+          module.set_base(address_value);
           // These addresses are absolute values.
           module.set_base_is_offset(false);
 
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -22,7 +22,6 @@
 #include "lldb/Host/Pipe.h"
 #include "lldb/Host/ProcessLaunchInfo.h"
 #include "lldb/Host/Socket.h"
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Host/ThreadLauncher.h"
 #include "lldb/Host/common/TCPSocket.h"
 #include "lldb/Host/posix/ConnectionFileDescriptorPosix.h"
@@ -1173,7 +1172,9 @@
             port_cstr, num_bytes, std::chrono::seconds{10}, num_bytes);
         if (error.Success() && (port != nullptr)) {
           assert(num_bytes > 0 && port_cstr[num_bytes - 1] == '\0');
-          uint16_t child_port = StringConvert::ToUInt32(port_cstr, 0);
+          uint16_t child_port = 0;
+          // FIXME: improve error handling
+          llvm::to_integer(port_cstr, child_port);
           if (*port == 0 || *port == child_port) {
             *port = child_port;
             LLDB_LOGF(log,
Index: lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
===================================================================
--- lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
+++ lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
@@ -10,7 +10,6 @@
 
 #include "lldb/Core/StreamFile.h"
 #include "lldb/DataFormatters/FormatManager.h"
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Interpreter/OptionArgParser.h"
 #include "lldb/Utility/ArchSpec.h"
 #include "lldb/Utility/RegularExpression.h"
@@ -142,11 +141,10 @@
           std::string reg_name_str = matches[1].str();
           std::string msbit_str = matches[2].str();
           std::string lsbit_str = matches[3].str();
-          const uint32_t msbit =
-              StringConvert::ToUInt32(msbit_str.c_str(), UINT32_MAX);
-          const uint32_t lsbit =
-              StringConvert::ToUInt32(lsbit_str.c_str(), UINT32_MAX);
-          if (msbit != UINT32_MAX && lsbit != UINT32_MAX) {
+          uint32_t msbit;
+          uint32_t lsbit;
+          if (llvm::to_integer(msbit_str, msbit) &&
+              llvm::to_integer(lsbit_str, lsbit)) {
             if (msbit > lsbit) {
               const uint32_t msbyte = msbit / 8;
               const uint32_t lsbyte = lsbit / 8;
Index: lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
===================================================================
--- lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
+++ lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
@@ -11,7 +11,6 @@
 #include "lldb/Core/Section.h"
 #include "lldb/Core/ValueObject.h"
 #include "lldb/Host/HostInfo.h"
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Scalar.h"
 #include "lldb/Utility/UriParser.h"
@@ -290,7 +289,8 @@
     return 0;
   }
 
-  m_sdk_version = StringConvert::ToUInt32(version_string.c_str());
+  // FIXME: improve error handling
+  llvm::to_integer(version_string, m_sdk_version);
   return m_sdk_version;
 }
 
Index: lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
===================================================================
--- lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
+++ lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
@@ -17,7 +17,6 @@
 #include "lldb/DataFormatters/DumpValueObjectOptions.h"
 #include "lldb/Expression/UserExpression.h"
 #include "lldb/Host/OptionParser.h"
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Interpreter/CommandObjectMultiword.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
@@ -4566,10 +4565,8 @@
             eLanguageTypeExtRenderScript));
 
     const char *id_cstr = command.GetArgumentAtIndex(0);
-    bool success = false;
-    const uint32_t id =
-        StringConvert::ToUInt32(id_cstr, UINT32_MAX, 0, &success);
-    if (!success) {
+    uint32_t id;
+    if (!llvm::to_integer(id_cstr, id)) {
       result.AppendErrorWithFormat("invalid allocation id argument '%s'",
                                    id_cstr);
       return false;
@@ -4713,10 +4710,8 @@
             eLanguageTypeExtRenderScript));
 
     const char *id_cstr = command.GetArgumentAtIndex(0);
-    bool success = false;
-    const uint32_t id =
-        StringConvert::ToUInt32(id_cstr, UINT32_MAX, 0, &success);
-    if (!success) {
+    uint32_t id;
+    if (!llvm::to_integer(id_cstr, id)) {
       result.AppendErrorWithFormat("invalid allocation id argument '%s'",
                                    id_cstr);
       return false;
@@ -4762,10 +4757,8 @@
             eLanguageTypeExtRenderScript));
 
     const char *id_cstr = command.GetArgumentAtIndex(0);
-    bool success = false;
-    const uint32_t id =
-        StringConvert::ToUInt32(id_cstr, UINT32_MAX, 0, &success);
-    if (!success) {
+    uint32_t id;
+    if (!llvm::to_integer(id_cstr, id)) {
       result.AppendErrorWithFormat("invalid allocation id argument '%s'",
                                    id_cstr);
       return false;
Index: lldb/source/Interpreter/Property.cpp
===================================================================
--- lldb/source/Interpreter/Property.cpp
+++ lldb/source/Interpreter/Property.cpp
@@ -9,7 +9,6 @@
 #include "lldb/Interpreter/Property.h"
 
 #include "lldb/Core/UserSettingsController.h"
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Interpreter/OptionArgParser.h"
 #include "lldb/Interpreter/OptionValues.h"
@@ -176,28 +175,32 @@
         std::make_shared<OptionValueRegex>(definition.default_cstr_value);
     break;
 
-  case OptionValue::eTypeSInt64:
+  case OptionValue::eTypeSInt64: {
     // "definition.default_uint_value" is the default integer value if
     // "definition.default_cstr_value" is NULL, otherwise interpret
     // "definition.default_cstr_value" as a string value that represents the
     // default value.
+    int64_t value = 0;
+    // FIXME: improve error handling for llvm::to_integer()
+    if (definition.default_cstr_value)
+      llvm::to_integer(definition.default_cstr_value, value);
     m_value_sp = std::make_shared<OptionValueSInt64>(
-        definition.default_cstr_value
-            ? StringConvert::ToSInt64(definition.default_cstr_value)
-            : definition.default_uint_value);
+        definition.default_cstr_value ? value : definition.default_uint_value);
     break;
-
-  case OptionValue::eTypeUInt64:
+  }
+  case OptionValue::eTypeUInt64: {
+    uint64_t value = 0;
+    // FIXME: improve error handling for llvm::to_integer()
+    if (definition.default_cstr_value)
+      llvm::to_integer(definition.default_cstr_value, value);
     // "definition.default_uint_value" is the default unsigned integer value if
     // "definition.default_cstr_value" is NULL, otherwise interpret
     // "definition.default_cstr_value" as a string value that represents the
     // default value.
     m_value_sp = std::make_shared<OptionValueUInt64>(
-        definition.default_cstr_value
-            ? StringConvert::ToUInt64(definition.default_cstr_value)
-            : definition.default_uint_value);
+        definition.default_cstr_value ? value : definition.default_uint_value);
     break;
-
+  }
   case OptionValue::eTypeUUID:
     // "definition.default_uint_value" is not used for a OptionValue::eTypeUUID
     // "definition.default_cstr_value" can contain a default UUID value
Index: lldb/source/Interpreter/OptionValueUInt64.cpp
===================================================================
--- lldb/source/Interpreter/OptionValueUInt64.cpp
+++ lldb/source/Interpreter/OptionValueUInt64.cpp
@@ -8,7 +8,6 @@
 
 #include "lldb/Interpreter/OptionValueUInt64.h"
 
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Utility/Stream.h"
 
 using namespace lldb;
@@ -45,16 +44,15 @@
 
   case eVarSetOperationReplace:
   case eVarSetOperationAssign: {
-    bool success = false;
-    std::string value_str = value_ref.trim().str();
-    uint64_t value = StringConvert::ToUInt64(value_str.c_str(), 0, 0, &success);
-    if (success) {
+    llvm::StringRef value_trimmed = value_ref.trim();
+    uint64_t value;
+    if (llvm::to_integer(value_trimmed, value)) {
       m_value_was_set = true;
       m_current_value = value;
       NotifyValueChanged();
     } else {
       error.SetErrorStringWithFormat("invalid uint64_t string value: '%s'",
-                                     value_str.c_str());
+                                     value_ref.str().c_str());
     }
   } break;
 
Index: lldb/source/Interpreter/OptionValueSInt64.cpp
===================================================================
--- lldb/source/Interpreter/OptionValueSInt64.cpp
+++ lldb/source/Interpreter/OptionValueSInt64.cpp
@@ -8,7 +8,6 @@
 
 #include "lldb/Interpreter/OptionValueSInt64.h"
 
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Utility/Stream.h"
 
 using namespace lldb;
@@ -41,10 +40,9 @@
 
   case eVarSetOperationReplace:
   case eVarSetOperationAssign: {
-    bool success = false;
-    std::string value_str = value_ref.trim().str();
-    int64_t value = StringConvert::ToSInt64(value_str.c_str(), 0, 0, &success);
-    if (success) {
+    llvm::StringRef value_trimmed = value_ref.trim();
+    int64_t value;
+    if (llvm::to_integer(value_trimmed, value)) {
       if (value >= m_min_value && value <= m_max_value) {
         m_value_was_set = true;
         m_current_value = value;
Index: lldb/source/Interpreter/OptionValuePathMappings.cpp
===================================================================
--- lldb/source/Interpreter/OptionValuePathMappings.cpp
+++ lldb/source/Interpreter/OptionValuePathMappings.cpp
@@ -9,7 +9,6 @@
 #include "lldb/Interpreter/OptionValuePathMappings.h"
 
 #include "lldb/Host/FileSystem.h"
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Utility/Args.h"
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/Stream.h"
@@ -52,13 +51,12 @@
     // Must be at least one index + 1 pair of paths, and the pair count must be
     // even
     if (argc >= 3 && (((argc - 1) & 1) == 0)) {
-      uint32_t idx =
-          StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
+      uint32_t idx;
       const uint32_t count = m_path_mappings.GetSize();
-      if (idx > count) {
+      if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
         error.SetErrorStringWithFormat(
-            "invalid file list index %u, index must be 0 through %u", idx,
-            count);
+            "invalid file list index %s, index must be 0 through %u",
+            args.GetArgumentAtIndex(0), count);
       } else {
         bool changed = false;
         for (size_t i = 1; i < argc; idx++, i += 2) {
@@ -128,13 +126,12 @@
     // Must be at least one index + 1 pair of paths, and the pair count must be
     // even
     if (argc >= 3 && (((argc - 1) & 1) == 0)) {
-      uint32_t idx =
-          StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
+      uint32_t idx;
       const uint32_t count = m_path_mappings.GetSize();
-      if (idx > count) {
+      if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
         error.SetErrorStringWithFormat(
-            "invalid file list index %u, index must be 0 through %u", idx,
-            count);
+            "invalid file list index %s, index must be 0 through %u",
+            args.GetArgumentAtIndex(0), count);
       } else {
         bool changed = false;
         if (op == eVarSetOperationInsertAfter)
@@ -169,9 +166,9 @@
     if (argc > 0) {
       std::vector<int> remove_indexes;
       for (size_t i = 0; i < argc; ++i) {
-        int idx =
-            StringConvert::ToSInt32(args.GetArgumentAtIndex(i), INT32_MAX);
-        if (idx < 0 || idx >= (int)m_path_mappings.GetSize()) {
+        int idx;
+        if (!llvm::to_integer(args.GetArgumentAtIndex(i), idx) || idx < 0 ||
+            idx >= (int)m_path_mappings.GetSize()) {
           error.SetErrorStringWithFormat(
               "invalid array index '%s', aborting remove operation",
               args.GetArgumentAtIndex(i));
Index: lldb/source/Interpreter/OptionValueFileSpecList.cpp
===================================================================
--- lldb/source/Interpreter/OptionValueFileSpecList.cpp
+++ lldb/source/Interpreter/OptionValueFileSpecList.cpp
@@ -8,7 +8,6 @@
 
 #include "lldb/Interpreter/OptionValueFileSpecList.h"
 
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Utility/Args.h"
 #include "lldb/Utility/Stream.h"
 
@@ -57,13 +56,12 @@
 
   case eVarSetOperationReplace:
     if (argc > 1) {
-      uint32_t idx =
-          StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
+      uint32_t idx;
       const uint32_t count = m_current_value.GetSize();
-      if (idx > count) {
+      if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
         error.SetErrorStringWithFormat(
-            "invalid file list index %u, index must be 0 through %u", idx,
-            count);
+            "invalid file list index %s, index must be 0 through %u",
+            args.GetArgumentAtIndex(0), count);
       } else {
         for (size_t i = 1; i < argc; ++i, ++idx) {
           FileSpec file(args.GetArgumentAtIndex(i));
@@ -101,13 +99,12 @@
   case eVarSetOperationInsertBefore:
   case eVarSetOperationInsertAfter:
     if (argc > 1) {
-      uint32_t idx =
-          StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
+      uint32_t idx;
       const uint32_t count = m_current_value.GetSize();
-      if (idx > count) {
+      if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
         error.SetErrorStringWithFormat(
-            "invalid insert file list index %u, index must be 0 through %u",
-            idx, count);
+            "invalid insert file list index %s, index must be 0 through %u",
+            args.GetArgumentAtIndex(0), count);
       } else {
         if (op == eVarSetOperationInsertAfter)
           ++idx;
@@ -129,9 +126,8 @@
       bool all_indexes_valid = true;
       size_t i;
       for (i = 0; all_indexes_valid && i < argc; ++i) {
-        const int idx =
-            StringConvert::ToSInt32(args.GetArgumentAtIndex(i), INT32_MAX);
-        if (idx == INT32_MAX)
+        int idx;
+        if (!llvm::to_integer(args.GetArgumentAtIndex(i), idx))
           all_indexes_valid = false;
         else
           remove_indexes.push_back(idx);
Index: lldb/source/Interpreter/OptionValueArray.cpp
===================================================================
--- lldb/source/Interpreter/OptionValueArray.cpp
+++ lldb/source/Interpreter/OptionValueArray.cpp
@@ -8,7 +8,6 @@
 
 #include "lldb/Interpreter/OptionValueArray.h"
 
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Utility/Args.h"
 #include "lldb/Utility/Stream.h"
 
@@ -167,13 +166,12 @@
   case eVarSetOperationInsertBefore:
   case eVarSetOperationInsertAfter:
     if (argc > 1) {
-      uint32_t idx =
-          StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
+      uint32_t idx;
       const uint32_t count = GetSize();
-      if (idx > count) {
+      if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
         error.SetErrorStringWithFormat(
-            "invalid insert array index %u, index must be 0 through %u", idx,
-            count);
+            "invalid insert array index %s, index must be 0 through %u",
+            args.GetArgumentAtIndex(0), count);
       } else {
         if (op == eVarSetOperationInsertAfter)
           ++idx;
@@ -207,9 +205,8 @@
       bool all_indexes_valid = true;
       size_t i;
       for (i = 0; i < argc; ++i) {
-        const size_t idx =
-            StringConvert::ToSInt32(args.GetArgumentAtIndex(i), INT32_MAX);
-        if (idx >= size) {
+        size_t idx;
+        if (!llvm::to_integer(args.GetArgumentAtIndex(i), idx) || idx >= size) {
           all_indexes_valid = false;
           break;
         } else
@@ -249,13 +246,12 @@
 
   case eVarSetOperationReplace:
     if (argc > 1) {
-      uint32_t idx =
-          StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
+      uint32_t idx;
       const uint32_t count = GetSize();
-      if (idx > count) {
+      if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
         error.SetErrorStringWithFormat(
-            "invalid replace array index %u, index must be 0 through %u", idx,
-            count);
+            "invalid replace array index %s, index must be 0 through %u",
+            args.GetArgumentAtIndex(0), count);
       } else {
         for (size_t i = 1; i < argc; ++i, ++idx) {
           lldb::OptionValueSP value_sp(CreateValueFromCStringForTypeMask(
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to