Fixed a crasher that could happen if a FileSpec had a filename only, or vice

versa.

llvm-svn: 116963
This commit is contained in:
Greg Clayton
2010-10-20 22:52:05 +00:00
parent a3b61d32d8
commit 58fc50e0e1
2 changed files with 16 additions and 17 deletions

View File

@@ -462,8 +462,11 @@ public:
///
/// @param[out] lines
/// The string array into which to read the file.
///
/// @result
/// Returns the number of lines that were read from the file.
//------------------------------------------------------------------
bool
size_t
ReadFileLines (STLStringArray &lines);
//------------------------------------------------------------------

View File

@@ -732,25 +732,21 @@ FileSpec::ReadFileContents (off_t file_offset, size_t file_size) const
return data_sp;
}
bool
size_t
FileSpec::ReadFileLines (STLStringArray &lines)
{
bool ret_val = false;
lines.clear();
std::string dir_str (m_directory.AsCString());
std::string file_str (m_filename.AsCString());
std::string full_name = dir_str + "/" + file_str;
ifstream file_stream (full_name.c_str());
if (file_stream)
char path[PATH_MAX];
if (GetPath(path, sizeof(path)))
{
std::string line;
while (getline (file_stream, line))
lines.push_back (line);
ret_val = true;
}
ifstream file_stream (path);
return ret_val;
if (file_stream)
{
std::string line;
while (getline (file_stream, line))
lines.push_back (line);
}
}
return lines.size();
}