mirror of
https://github.com/intel/llvm.git
synced 2026-01-16 13:35:38 +08:00
Fixed a crasher that could happen if a FileSpec had a filename only, or vice
versa. llvm-svn: 116963
This commit is contained in:
@@ -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);
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user