Start converting usages of off_t to other types.
off_t is a type which is used for file offsets. Even more
specifically, it is only used by a limited number of C APIs that
deal with files. Any usage of off_t where the variable is not
intended to be used with one of these APIs is a bug, by definition.
This patch corrects some easy mis-uses of off_t, generally by
converting them to lldb::offset_t, but sometimes by using other
types such as size_t, when appropriate.
The use of off_t to represent these offsets has worked fine in
practice on linux-y platforms, since we used _FILE_OFFSET_64 to
guarantee that off_t was a uint64. On Windows, however,
_FILE_OFFSET_64 is unrecognized, and off_t will always be 32-bit.
So the usage of off_t on Windows actually leads to legitimate bugs.
Reviewed by: Greg Clayton
Differential Revision: http://reviews.llvm.org/D4358
llvm-svn: 212192
diff --git a/lldb/source/Symbol/ObjectFile.cpp b/lldb/source/Symbol/ObjectFile.cpp
index 962ae00..11b5400 100644
--- a/lldb/source/Symbol/ObjectFile.cpp
+++ b/lldb/source/Symbol/ObjectFile.cpp
@@ -439,7 +439,7 @@
}
size_t
-ObjectFile::GetData (off_t offset, size_t length, DataExtractor &data) const
+ObjectFile::GetData (lldb::offset_t offset, size_t length, DataExtractor &data) const
{
// The entire file has already been mmap'ed into m_data, so just copy from there
// as the back mmap buffer will be shared with shared pointers.
@@ -447,7 +447,7 @@
}
size_t
-ObjectFile::CopyData (off_t offset, size_t length, void *dst) const
+ObjectFile::CopyData (lldb::offset_t offset, size_t length, void *dst) const
{
// The entire file has already been mmap'ed into m_data, so just copy from there
// Note that the data remains in target byte order.
@@ -456,7 +456,7 @@
size_t
-ObjectFile::ReadSectionData (const Section *section, off_t section_offset, void *dst, size_t dst_len) const
+ObjectFile::ReadSectionData (const Section *section, lldb::offset_t section_offset, void *dst, size_t dst_len) const
{
// If some other objectfile owns this data, pass this to them.
if (section->GetObjectFile() != this)
@@ -475,11 +475,11 @@
}
else
{
- const uint64_t section_file_size = section->GetFileSize();
- if (section_offset < static_cast<off_t>(section_file_size))
+ const lldb::offset_t section_file_size = section->GetFileSize();
+ if (section_offset < section_file_size)
{
- const uint64_t section_bytes_left = section_file_size - section_offset;
- uint64_t section_dst_len = dst_len;
+ const size_t section_bytes_left = section_file_size - section_offset;
+ size_t section_dst_len = dst_len;
if (section_dst_len > section_bytes_left)
section_dst_len = section_bytes_left;
return CopyData (section->GetFileOffset() + section_offset, section_dst_len, dst);