From f6099df1948d7a12cae2c29a51e5cae8f4f3e8b7 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 19 Apr 2003 21:45:17 +0000 Subject: [PATCH] Add support for reading unaligned bytecode buffers git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5819 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bytecode/Reader/Reader.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index 60116af7ac8..3e495f48604 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -639,8 +639,19 @@ Module *BytecodeParser::ParseBytecode(const uchar *Buf, const uchar *EndBuf) { Module *ParseBytecodeBuffer(const unsigned char *Buffer, unsigned Length, std::string *ErrorStr) { BytecodeParser Parser; + unsigned char *PtrToDelete = 0; + if ((intptr_t)Buffer & 3) { // If the buffer is not 4 byte aligned... + // Allocate a new buffer to hold the bytecode... + PtrToDelete = new unsigned char[Length+4]; + unsigned Offset = 4-((intptr_t)PtrToDelete & 3); // Make sure it's aligned + memcpy(PtrToDelete+Offset, Buffer, Length); // Copy it over + Buffer = PtrToDelete+Offset; + } + Module *R = Parser.ParseBytecode(Buffer, Buffer+Length); if (ErrorStr) *ErrorStr = Parser.getError(); + + delete [] PtrToDelete; // Delete alignment buffer if neccesary return R; }