[lld] r186888 - [PECOFF] Replace magic numbers with offsetof().
Rui Ueyama
ruiu at google.com
Mon Jul 22 16:02:08 PDT 2013
Author: ruiu
Date: Mon Jul 22 18:02:08 2013
New Revision: 186888
URL: http://llvm.org/viewvc/llvm-project?rev=186888&view=rev
Log:
[PECOFF] Replace magic numbers with offsetof().
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp
Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp?rev=186888&r1=186887&r2=186888&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp Mon Jul 22 18:02:08 2013
@@ -170,8 +170,8 @@ public:
const char *end = mb->getBufferEnd();
// The size of the string that follows the header.
- uint32_t dataSize =
- *reinterpret_cast<const support::ulittle32_t *>(buf + 12);
+ uint32_t dataSize = *reinterpret_cast<const support::ulittle32_t *>(
+ buf + offsetof(COFF::ImportHeader, SizeOfData));
// Check if the total size is valid. The file header is 20 byte long.
if (end - buf != 20 + dataSize) {
@@ -179,13 +179,15 @@ public:
return;
}
- uint16_t hint = *reinterpret_cast<const support::ulittle16_t *>(buf + 16);
+ uint16_t hint = *reinterpret_cast<const support::ulittle16_t *>(
+ buf + offsetof(COFF::ImportHeader, OrdinalHint));
StringRef symbolName(buf + 20);
StringRef dllName(buf + 20 + symbolName.size() + 1);
const COFFSharedLibraryAtom *dataAtom = addSharedLibraryAtom(
hint, symbolName, dllName);
- int type = *reinterpret_cast<const support::ulittle16_t *>(buf + 18) >> 16;
+ int type = *reinterpret_cast<const support::ulittle16_t *>(
+ buf + offsetof(COFF::ImportHeader, TypeInfo)) >> 14;
if (type == llvm::COFF::IMPORT_CODE)
addDefinedAtom(symbolName, dllName, dataAtom);
More information about the llvm-commits
mailing list