<rdar://problem/10652336>
Fixed a crasher when trying to load an expression prefix file:
% touch /tmp/carp.txt
% xcrun lldb
(lldb) settings set target.expr-prefix /tmp/carp.txt
Segmentation fault
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@147646 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Target/Target.cpp b/source/Target/Target.cpp
index c31b0b1..3ff461d 100644
--- a/source/Target/Target.cpp
+++ b/source/Target/Target.cpp
@@ -2308,6 +2308,8 @@
case eVarSetOperationAssign:
case eVarSetOperationAppend:
{
+ m_expr_prefix_contents.clear();
+
if (!m_expr_prefix_file.GetCurrentValue().Exists())
{
err.SetErrorToGenericError ();
@@ -2315,15 +2317,19 @@
return;
}
- DataBufferSP file_contents = m_expr_prefix_file.GetCurrentValue().ReadFileContents();
+ DataBufferSP file_data_sp (m_expr_prefix_file.GetCurrentValue().ReadFileContents(0, SIZE_MAX, &err));
- if (!file_contents && file_contents->GetByteSize() == 0)
+ if (err.Success())
{
- err.SetErrorStringWithFormat ("couldn't read data from '%s'", value);
- m_expr_prefix_contents.clear();
+ if (file_data_sp && file_data_sp->GetByteSize() > 0)
+ {
+ m_expr_prefix_contents.assign((const char*)file_data_sp->GetBytes(), file_data_sp->GetByteSize());
+ }
+ else
+ {
+ err.SetErrorStringWithFormat ("couldn't read data from '%s'", value);
+ }
}
-
- m_expr_prefix_contents.assign((const char*)file_contents->GetBytes(), file_contents->GetByteSize());
}
break;
case eVarSetOperationClear: