[Lldb-commits] [lldb] 1c1ffa6 - GetPath() returns a std::string temporary. You can't reference just the c_str.

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 5 19:13:46 PDT 2020


Author: Jim Ingham
Date: 2020-08-05T19:12:15-07:00
New Revision: 1c1ffa6a300a60c81be41a3e08a4e9da7499adc1

URL: https://github.com/llvm/llvm-project/commit/1c1ffa6a300a60c81be41a3e08a4e9da7499adc1
DIFF: https://github.com/llvm/llvm-project/commit/1c1ffa6a300a60c81be41a3e08a4e9da7499adc1.diff

LOG: GetPath() returns a std::string temporary.  You can't reference just the c_str.

Found by the static analyzer.

Added: 
    

Modified: 
    lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 338c798e6cef..383cc5b59a37 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1887,15 +1887,15 @@ class MachSymtabSectionInfo {
           m_section_infos[n_sect].vm_range.SetByteSize(
               section_sp->GetByteSize());
         } else {
-          const char *filename = "<unknown>";
+          std::string filename = "<unknown>";
           SectionSP first_section_sp(m_section_list->GetSectionAtIndex(0));
           if (first_section_sp)
-            filename = first_section_sp->GetObjectFile()->GetFileSpec().GetPath().c_str();
+            filename = first_section_sp->GetObjectFile()->GetFileSpec().GetPath();
 
           Host::SystemLog(Host::eSystemLogError,
                           "error: unable to find section %d for a symbol in %s, corrupt file?\n",
                           n_sect, 
-                          filename);
+                          filename.c_str());
         }
       }
       if (m_section_infos[n_sect].vm_range.Contains(file_addr)) {


        


More information about the lldb-commits mailing list