This revision was automatically updated to reflect the committed changes.
Closed by commit rG9010cef2af0a: [lldb] Replace StringConvert with 
llvm::to_integer when parsing integer values… (authored by teemperor).
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Changed prior to commit:
  https://reviews.llvm.org/D82297?vs=272401&id=274827#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82297

Files:
  lldb/source/Commands/CommandObjectFrame.cpp
  lldb/source/Commands/CommandObjectPlatform.cpp
  lldb/source/Commands/CommandObjectProcess.cpp
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/source/Commands/CommandObjectThread.cpp
  lldb/test/API/commands/frame/recognizer/TestFrameRecognizer.py
  lldb/test/API/commands/platform/file/close/TestPlatformFileClose.py
  lldb/test/API/commands/platform/file/read/TestPlatformFileRead.py
  lldb/test/API/commands/process/signal/Makefile
  lldb/test/API/commands/process/signal/TestProcessSignal.py
  lldb/test/API/commands/process/signal/main.cpp
  lldb/test/API/commands/target/modules/search-paths/insert/Makefile
  
lldb/test/API/commands/target/modules/search-paths/insert/TestTargetModulesSearchpathsInsert.py
  lldb/test/API/commands/target/modules/search-paths/insert/main.cpp
  lldb/test/API/commands/target/select/TestTargetSelect.py
  lldb/test/API/commands/target/stop-hook/delete/TestTargetStopHookDelete.py
  lldb/test/API/commands/target/stop-hook/disable/TestTargetStopHookDisable.py
  lldb/test/API/commands/target/stop-hook/enable/TestTargetStopHookEnable.py
  lldb/test/API/commands/thread/select/Makefile
  lldb/test/API/commands/thread/select/TestThreadSelect.py
  lldb/test/API/commands/thread/select/main.cpp

Index: lldb/test/API/commands/thread/select/main.cpp
===================================================================
--- /dev/null
+++ lldb/test/API/commands/thread/select/main.cpp
@@ -0,0 +1,3 @@
+int main() {
+  return 0; // break here
+}
Index: lldb/test/API/commands/thread/select/TestThreadSelect.py
===================================================================
--- /dev/null
+++ lldb/test/API/commands/thread/select/TestThreadSelect.py
@@ -0,0 +1,18 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test.decorators import *
+
+class TestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    def test_invalid_arg(self):
+        self.build()
+
+        lldbutil.run_to_source_breakpoint(self, '// break here', lldb.SBFileSpec("main.cpp"))
+
+        self.expect("thread select -1", error=True, startstr="error: Invalid thread index '-1'")
+        self.expect("thread select 0x1ffffffff", error=True, startstr="error: Invalid thread index '0x1ffffffff'")
+        # Parses but not a valid thread id.
+        self.expect("thread select 0xffffffff", error=True, startstr="error: invalid thread #0xffffffff.")
Index: lldb/test/API/commands/thread/select/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/commands/thread/select/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
Index: lldb/test/API/commands/target/stop-hook/enable/TestTargetStopHookEnable.py
===================================================================
--- /dev/null
+++ lldb/test/API/commands/target/stop-hook/enable/TestTargetStopHookEnable.py
@@ -0,0 +1,15 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @no_debug_info_test
+    def test_invalid_arg(self):
+        self.expect("target stop-hook enable -1", error=True,
+                    startstr="error: invalid stop hook id: \"-1\".")
+        self.expect("target stop-hook enable abcdfx", error=True,
+                    startstr="error: invalid stop hook id: \"abcdfx\".")
Index: lldb/test/API/commands/target/stop-hook/disable/TestTargetStopHookDisable.py
===================================================================
--- /dev/null
+++ lldb/test/API/commands/target/stop-hook/disable/TestTargetStopHookDisable.py
@@ -0,0 +1,15 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @no_debug_info_test
+    def test_invalid_arg(self):
+        self.expect("target stop-hook disable -1", error=True,
+                    startstr="error: invalid stop hook id: \"-1\".")
+        self.expect("target stop-hook disable abcdfx", error=True,
+                    startstr="error: invalid stop hook id: \"abcdfx\".")
Index: lldb/test/API/commands/target/stop-hook/delete/TestTargetStopHookDelete.py
===================================================================
--- /dev/null
+++ lldb/test/API/commands/target/stop-hook/delete/TestTargetStopHookDelete.py
@@ -0,0 +1,15 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @no_debug_info_test
+    def test_invalid_arg(self):
+        self.expect("target stop-hook delete -1", error=True,
+                    startstr="error: invalid stop hook id: \"-1\".")
+        self.expect("target stop-hook delete abcdfx", error=True,
+                    startstr="error: invalid stop hook id: \"abcdfx\".")
Index: lldb/test/API/commands/target/select/TestTargetSelect.py
===================================================================
--- /dev/null
+++ lldb/test/API/commands/target/select/TestTargetSelect.py
@@ -0,0 +1,15 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @no_debug_info_test
+    def test_invalid_arg(self):
+        self.expect("target select -1", error=True,
+                    startstr="error: invalid index string value '-1'")
+        self.expect("target select abcdfx", error=True,
+                    startstr="error: invalid index string value 'abcdfx'")
Index: lldb/test/API/commands/target/modules/search-paths/insert/main.cpp
===================================================================
--- /dev/null
+++ lldb/test/API/commands/target/modules/search-paths/insert/main.cpp
@@ -0,0 +1 @@
+int main() { return 0; }
Index: lldb/test/API/commands/target/modules/search-paths/insert/TestTargetModulesSearchpathsInsert.py
===================================================================
--- /dev/null
+++ lldb/test/API/commands/target/modules/search-paths/insert/TestTargetModulesSearchpathsInsert.py
@@ -0,0 +1,20 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+import lldbsuite.test.lldbutil as lldbutil
+
+class TestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @no_debug_info_test
+    def test_invalid_arg(self):
+        self.build()
+        exe = self.getBuildArtifact("a.out")
+
+        self.expect("target create %s" % (exe))
+        self.expect("target modules search-paths insert -1 a b", error=True,
+                    startstr="error: <index> parameter is not an integer: '-1'.")
+
+        self.expect("target modules search-paths insert abcdefx a b", error=True,
+                    startstr="error: <index> parameter is not an integer: 'abcdefx'.")
Index: lldb/test/API/commands/target/modules/search-paths/insert/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/commands/target/modules/search-paths/insert/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
Index: lldb/test/API/commands/process/signal/main.cpp
===================================================================
--- /dev/null
+++ lldb/test/API/commands/process/signal/main.cpp
@@ -0,0 +1,3 @@
+int main() {
+  return 0; // break here
+}
Index: lldb/test/API/commands/process/signal/TestProcessSignal.py
===================================================================
--- /dev/null
+++ lldb/test/API/commands/process/signal/TestProcessSignal.py
@@ -0,0 +1,17 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test.decorators import *
+
+class TestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @no_debug_info_test
+    def test_invalid_arg(self):
+        self.build()
+
+        lldbutil.run_to_source_breakpoint(self, '// break here', lldb.SBFileSpec("main.cpp"))
+        self.expect("process signal az", error=True, startstr="error: Invalid signal argument 'az'.")
+        self.expect("process signal 0x1ffffffff", error=True, startstr="error: Invalid signal argument '0x1ffffffff'.")
+        self.expect("process signal 0xffffffff", error=True, startstr="error: Invalid signal argument '0xffffffff'.")
Index: lldb/test/API/commands/process/signal/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/commands/process/signal/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
Index: lldb/test/API/commands/platform/file/read/TestPlatformFileRead.py
===================================================================
--- /dev/null
+++ lldb/test/API/commands/platform/file/read/TestPlatformFileRead.py
@@ -0,0 +1,16 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @no_debug_info_test
+    def test_file_close_invalid_arg(self):
+        self.expect("platform file read y", error=True,
+                    substrs=["'y' is not a valid file descriptor."])
+        # 'file read' takes an option, so this will be treated as an option.
+        self.expect("platform file read -1", error=True,
+                    substrs=["unknown or ambiguous option"])
Index: lldb/test/API/commands/platform/file/close/TestPlatformFileClose.py
===================================================================
--- /dev/null
+++ lldb/test/API/commands/platform/file/close/TestPlatformFileClose.py
@@ -0,0 +1,15 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @no_debug_info_test
+    def test_file_close_invalid_arg(self):
+        self.expect("platform file close y", error=True,
+                    substrs=["'y' is not a valid file descriptor."])
+        self.expect("platform file close -1", error=True,
+                    substrs=["'-1' is not a valid file descriptor."])
Index: lldb/test/API/commands/frame/recognizer/TestFrameRecognizer.py
===================================================================
--- lldb/test/API/commands/frame/recognizer/TestFrameRecognizer.py
+++ lldb/test/API/commands/frame/recognizer/TestFrameRecognizer.py
@@ -144,3 +144,25 @@
 
         self.expect("frame recognizer info 0",
                     substrs=['frame 0 is recognized by recognizer.MyFrameRecognizer'])
+
+    @no_debug_info_test
+    def test_frame_recognizer_delete_invalid_arg(self):
+        self.expect("frame recognizer delete a", error=True,
+                    substrs=["error: 'a' is not a valid recognizer id."])
+        self.expect("frame recognizer delete \"\"", error=True,
+                    substrs=["error: '' is not a valid recognizer id."])
+        self.expect("frame recognizer delete -1", error=True,
+                    substrs=["error: '-1' is not a valid recognizer id."])
+        self.expect("frame recognizer delete 4294967297", error=True,
+                    substrs=["error: '4294967297' is not a valid recognizer id."])
+
+    @no_debug_info_test
+    def test_frame_recognizer_info_invalid_arg(self):
+        self.expect("frame recognizer info a", error=True,
+                    substrs=["error: 'a' is not a valid frame index."])
+        self.expect("frame recognizer info \"\"", error=True,
+                    substrs=["error: '' is not a valid frame index."])
+        self.expect("frame recognizer info -1", error=True,
+                    substrs=["error: '-1' is not a valid frame index."])
+        self.expect("frame recognizer info 4294967297", error=True,
+                    substrs=["error: '4294967297' is not a valid frame index."])
Index: lldb/source/Commands/CommandObjectThread.cpp
===================================================================
--- lldb/source/Commands/CommandObjectThread.cpp
+++ lldb/source/Commands/CommandObjectThread.cpp
@@ -10,7 +10,6 @@
 
 #include "lldb/Core/ValueObject.h"
 #include "lldb/Host/OptionParser.h"
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Interpreter/OptionArgParser.h"
@@ -109,11 +108,8 @@
           process->GetThreadList().GetMutex());
 
       for (size_t i = 0; i < num_args; i++) {
-        bool success;
-
-        uint32_t thread_idx = StringConvert::ToUInt32(
-            command.GetArgumentAtIndex(i), 0, 0, &success);
-        if (!success) {
+        uint32_t thread_idx;
+        if (!llvm::to_integer(command.GetArgumentAtIndex(i), thread_idx)) {
           result.AppendErrorWithFormat("invalid thread specification: \"%s\"\n",
                                        command.GetArgumentAtIndex(i));
           result.SetStatus(eReturnStatusFailed);
@@ -565,9 +561,9 @@
       }
     } else {
       const char *thread_idx_cstr = command.GetArgumentAtIndex(0);
-      uint32_t step_thread_idx =
-          StringConvert::ToUInt32(thread_idx_cstr, LLDB_INVALID_INDEX32);
-      if (step_thread_idx == LLDB_INVALID_INDEX32) {
+      uint32_t step_thread_idx;
+
+      if (!llvm::to_integer(thread_idx_cstr, step_thread_idx)) {
         result.AppendErrorWithFormat("invalid thread index '%s'.\n",
                                      thread_idx_cstr);
         result.SetStatus(eReturnStatusFailed);
@@ -1095,9 +1091,7 @@
         size_t num_args = command.GetArgumentCount();
         for (size_t i = 0; i < num_args; i++) {
           uint32_t line_number;
-          line_number = StringConvert::ToUInt32(command.GetArgumentAtIndex(i),
-                                                UINT32_MAX);
-          if (line_number == UINT32_MAX) {
+          if (!llvm::to_integer(command.GetArgumentAtIndex(i), line_number)) {
             result.AppendErrorWithFormat("invalid line number: '%s'.\n",
                                          command.GetArgumentAtIndex(i));
             result.SetStatus(eReturnStatusFailed);
@@ -1321,8 +1315,13 @@
       return false;
     }
 
-    uint32_t index_id =
-        StringConvert::ToUInt32(command.GetArgumentAtIndex(0), 0, 0);
+    uint32_t index_id;
+    if (!llvm::to_integer(command.GetArgumentAtIndex(0), index_id)) {
+      result.AppendErrorWithFormat("Invalid thread index '%s'",
+                                   command.GetArgumentAtIndex(0));
+      result.SetStatus(eReturnStatusFailed);
+      return false;
+    }
 
     Thread *new_thread =
         process->GetThreadList().FindThreadByIndexID(index_id).get();
@@ -1989,10 +1988,8 @@
       return false;
     }
 
-    bool success;
-    uint32_t thread_plan_idx =
-        StringConvert::ToUInt32(args.GetArgumentAtIndex(0), 0, 0, &success);
-    if (!success) {
+    uint32_t thread_plan_idx;
+    if (!llvm::to_integer(args.GetArgumentAtIndex(0), thread_plan_idx)) {
       result.AppendErrorWithFormat(
           "Invalid thread index: \"%s\" - should be unsigned int.",
           args.GetArgumentAtIndex(0));
@@ -2066,11 +2063,8 @@
         process->GetThreadList().GetMutex());
 
     for (size_t i = 0; i < num_args; i++) {
-      bool success;
-
-      lldb::tid_t tid = StringConvert::ToUInt64(
-          args.GetArgumentAtIndex(i), 0, 0, &success);
-      if (!success) {
+      lldb::tid_t tid;
+      if (!llvm::to_integer(args.GetArgumentAtIndex(i), tid)) {
         result.AppendErrorWithFormat("invalid thread specification: \"%s\"\n",
                                      args.GetArgumentAtIndex(i));
         result.SetStatus(eReturnStatusFailed);
Index: lldb/source/Commands/CommandObjectTarget.cpp
===================================================================
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -16,7 +16,6 @@
 #include "lldb/Core/ValueObjectVariable.h"
 #include "lldb/DataFormatters/ValueObjectPrinter.h"
 #include "lldb/Host/OptionParser.h"
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Interpreter/OptionArgParser.h"
@@ -506,11 +505,9 @@
 protected:
   bool DoExecute(Args &args, CommandReturnObject &result) override {
     if (args.GetArgumentCount() == 1) {
-      bool success = false;
       const char *target_idx_arg = args.GetArgumentAtIndex(0);
-      uint32_t target_idx =
-          StringConvert::ToUInt32(target_idx_arg, UINT32_MAX, 0, &success);
-      if (success) {
+      uint32_t target_idx;
+      if (llvm::to_integer(target_idx_arg, target_idx)) {
         TargetList &target_list = GetDebugger().GetTargetList();
         const uint32_t num_targets = target_list.GetNumTargets();
         if (target_idx < num_targets) {
@@ -1176,12 +1173,9 @@
     size_t argc = command.GetArgumentCount();
     // check for at least 3 arguments and an odd number of parameters
     if (argc >= 3 && argc & 1) {
-      bool success = false;
+      uint32_t insert_idx;
 
-      uint32_t insert_idx = StringConvert::ToUInt32(
-          command.GetArgumentAtIndex(0), UINT32_MAX, 0, &success);
-
-      if (!success) {
+      if (!llvm::to_integer(command.GetArgumentAtIndex(0), insert_idx)) {
         result.AppendErrorWithFormat(
             "<index> parameter is not an integer: '%s'.\n",
             command.GetArgumentAtIndex(0));
@@ -2748,10 +2742,8 @@
                   const char *load_addr_cstr = args.GetArgumentAtIndex(i + 1);
                   if (sect_name && load_addr_cstr) {
                     ConstString const_sect_name(sect_name);
-                    bool success = false;
-                    addr_t load_addr = StringConvert::ToUInt64(
-                        load_addr_cstr, LLDB_INVALID_ADDRESS, 0, &success);
-                    if (success) {
+                    addr_t load_addr;
+                    if (llvm::to_integer(load_addr_cstr, load_addr)) {
                       SectionSP section_sp(
                           section_list->FindSectionByName(const_sect_name));
                       if (section_sp) {
@@ -4732,18 +4724,15 @@
         target.RemoveAllStopHooks();
       }
     } else {
-      bool success;
       for (size_t i = 0; i < num_args; i++) {
-        lldb::user_id_t user_id = StringConvert::ToUInt32(
-            command.GetArgumentAtIndex(i), 0, 0, &success);
-        if (!success) {
+        lldb::user_id_t user_id;
+        if (!llvm::to_integer(command.GetArgumentAtIndex(i), user_id)) {
           result.AppendErrorWithFormat("invalid stop hook id: \"%s\".\n",
                                        command.GetArgumentAtIndex(i));
           result.SetStatus(eReturnStatusFailed);
           return false;
         }
-        success = target.RemoveStopHookByID(user_id);
-        if (!success) {
+        if (!target.RemoveStopHookByID(user_id)) {
           result.AppendErrorWithFormat("unknown stop hook id: \"%s\".\n",
                                        command.GetArgumentAtIndex(i));
           result.SetStatus(eReturnStatusFailed);
@@ -4781,9 +4770,8 @@
       target.SetAllStopHooksActiveState(m_enable);
     } else {
       for (size_t i = 0; i < num_args; i++) {
-        lldb::user_id_t user_id = StringConvert::ToUInt32(
-            command.GetArgumentAtIndex(i), 0, 0, &success);
-        if (!success) {
+        lldb::user_id_t user_id;
+        if (!llvm::to_integer(command.GetArgumentAtIndex(i), user_id)) {
           result.AppendErrorWithFormat("invalid stop hook id: \"%s\".\n",
                                        command.GetArgumentAtIndex(i));
           result.SetStatus(eReturnStatusFailed);
Index: lldb/source/Commands/CommandObjectProcess.cpp
===================================================================
--- lldb/source/Commands/CommandObjectProcess.cpp
+++ lldb/source/Commands/CommandObjectProcess.cpp
@@ -13,7 +13,6 @@
 #include "lldb/Core/Module.h"
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Host/OptionParser.h"
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Interpreter/OptionArgParser.h"
@@ -1059,10 +1058,10 @@
       int signo = LLDB_INVALID_SIGNAL_NUMBER;
 
       const char *signal_name = command.GetArgumentAtIndex(0);
-      if (::isxdigit(signal_name[0]))
-        signo =
-            StringConvert::ToSInt32(signal_name, LLDB_INVALID_SIGNAL_NUMBER, 0);
-      else
+      if (::isxdigit(signal_name[0])) {
+        if (!llvm::to_integer(signal_name, signo))
+          signo = LLDB_INVALID_SIGNAL_NUMBER;
+      } else
         signo = process->GetUnixSignals()->GetSignalNumberFromName(signal_name);
 
       if (signo == LLDB_INVALID_SIGNAL_NUMBER) {
@@ -1410,7 +1409,8 @@
       real_value = 0;
     else {
       // If the value isn't 'true' or 'false', it had better be 0 or 1.
-      real_value = StringConvert::ToUInt32(option.c_str(), 3);
+      if (!llvm::to_integer(option, real_value))
+        real_value = 3;
       if (real_value != 0 && real_value != 1)
         okay = false;
     }
Index: lldb/source/Commands/CommandObjectPlatform.cpp
===================================================================
--- lldb/source/Commands/CommandObjectPlatform.cpp
+++ lldb/source/Commands/CommandObjectPlatform.cpp
@@ -11,7 +11,6 @@
 #include "lldb/Core/Module.h"
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Host/OptionParser.h"
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Interpreter/CommandOptionValidators.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
@@ -546,8 +545,13 @@
     if (platform_sp) {
       std::string cmd_line;
       args.GetCommandString(cmd_line);
-      const lldb::user_id_t fd =
-          StringConvert::ToUInt64(cmd_line.c_str(), UINT64_MAX);
+      lldb::user_id_t fd;
+      if (!llvm::to_integer(cmd_line, fd)) {
+        result.AppendErrorWithFormatv("'{0}' is not a valid file descriptor.\n",
+                                      cmd_line);
+        result.SetStatus(eReturnStatusFailed);
+        return result.Succeeded();
+      }
       Status error;
       bool success = platform_sp->CloseFile(fd, error);
       if (success) {
@@ -586,8 +590,13 @@
     if (platform_sp) {
       std::string cmd_line;
       args.GetCommandString(cmd_line);
-      const lldb::user_id_t fd =
-          StringConvert::ToUInt64(cmd_line.c_str(), UINT64_MAX);
+      lldb::user_id_t fd;
+      if (!llvm::to_integer(cmd_line, fd)) {
+        result.AppendErrorWithFormatv("'{0}' is not a valid file descriptor.\n",
+                                      cmd_line);
+        result.SetStatus(eReturnStatusFailed);
+        return result.Succeeded();
+      }
       std::string buffer(m_options.m_count, 0);
       Status error;
       uint32_t retcode = platform_sp->ReadFile(
@@ -674,8 +683,13 @@
       std::string cmd_line;
       args.GetCommandString(cmd_line);
       Status error;
-      const lldb::user_id_t fd =
-          StringConvert::ToUInt64(cmd_line.c_str(), UINT64_MAX);
+      lldb::user_id_t fd;
+      if (!llvm::to_integer(cmd_line, fd)) {
+        result.AppendErrorWithFormatv("'{0}' is not a valid file descriptor.",
+                                      cmd_line);
+        result.SetStatus(eReturnStatusFailed);
+        return result.Succeeded();
+      }
       uint32_t retcode =
           platform_sp->WriteFile(fd, m_options.m_offset, &m_options.m_data[0],
                                  m_options.m_data.size(), error);
Index: lldb/source/Commands/CommandObjectFrame.cpp
===================================================================
--- lldb/source/Commands/CommandObjectFrame.cpp
+++ lldb/source/Commands/CommandObjectFrame.cpp
@@ -12,7 +12,6 @@
 #include "lldb/DataFormatters/ValueObjectPrinter.h"
 #include "lldb/Host/Config.h"
 #include "lldb/Host/OptionParser.h"
-#include "lldb/Host/StringConvert.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Interpreter/OptionGroupFormat.h"
@@ -986,8 +985,13 @@
       return false;
     }
 
-    uint32_t recognizer_id =
-        StringConvert::ToUInt32(command.GetArgumentAtIndex(0), 0, 0);
+    uint32_t recognizer_id;
+    if (!llvm::to_integer(command.GetArgumentAtIndex(0), recognizer_id)) {
+      result.AppendErrorWithFormat("'%s' is not a valid recognizer id.\n",
+                                   command.GetArgumentAtIndex(0));
+      result.SetStatus(eReturnStatusFailed);
+      return false;
+    }
 
     StackFrameRecognizerManager::RemoveRecognizerWithID(recognizer_id);
     result.SetStatus(eReturnStatusSuccessFinishResult);
@@ -1067,6 +1071,15 @@
 
 protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
+    const char *frame_index_str = command.GetArgumentAtIndex(0);
+    uint32_t frame_index;
+    if (!llvm::to_integer(frame_index_str, frame_index)) {
+      result.AppendErrorWithFormat("'%s' is not a valid frame index.",
+                                   frame_index_str);
+      result.SetStatus(eReturnStatusFailed);
+      return false;
+    }
+
     Process *process = m_exe_ctx.GetProcessPtr();
     if (process == nullptr) {
       result.AppendError("no process");
@@ -1086,8 +1099,6 @@
       return false;
     }
 
-    uint32_t frame_index =
-        StringConvert::ToUInt32(command.GetArgumentAtIndex(0), 0, 0);
     StackFrameSP frame_sp = thread->GetStackFrameAtIndex(frame_index);
     if (!frame_sp) {
       result.AppendErrorWithFormat("no frame with index %u", frame_index);
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to