GetPath() returns a std::string temporary. You can't reference just the c_str.
authorJim Ingham <jingham@apple.com>
Thu, 6 Aug 2020 02:12:15 +0000 (19:12 -0700)
committerJim Ingham <jingham@apple.com>
Thu, 6 Aug 2020 02:12:15 +0000 (19:12 -0700)
Found by the static analyzer.

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

index 338c798..383cc5b 100644 (file)
@@ -1887,15 +1887,15 @@ public:
           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)) {