[llvm] r221794 - Return the number of read bytes in MemoryObject::readBytes.
Jay Foad
jay.foad at gmail.com
Thu Nov 13 01:44:50 PST 2014
On 12 November 2014 17:11, Rafael Espindola <rafael.espindola at gmail.com> wrote:
> -int RawMemoryObject::readBytes(uint64_t address,
> - uint64_t size,
> - uint8_t *buf) const {
> - if (!validAddress(address) || !validAddress(address + size - 1)) return -1;
> - memcpy(buf, (uint8_t *)(uintptr_t)(address + FirstChar), size);
> - return size;
> +uint64_t RawMemoryObject::readBytes(uint8_t *Buf, uint64_t Size,
> + uint64_t Address) const {
> + uint64_t BufferSize = LastChar - FirstChar;
> + if (Address >= BufferSize)
> + return 0;
> +
> + uint64_t End = Address + Size;
> + if (End > BufferSize)
> + End = BufferSize;
> +
> + Size = End - Address;
> + assert(Size >= 0);
/home/admin/llvm-project/llvm/lib/Support/StreamingMemoryObject.cpp:63:18:
warning: comparison of unsigned expression >= 0 is always true
[-Wtype-limits]
> + memcpy(Buf, (uint8_t *)(Address + FirstChar), Size);
> + return Size;
> }
>
> const uint8_t *RawMemoryObject::getPointer(uint64_t address,
> @@ -91,12 +99,20 @@ uint64_t StreamingMemoryObject::getExten
> return ObjectSize;
> }
>
> -int StreamingMemoryObject::readBytes(uint64_t address,
> - uint64_t size,
> - uint8_t *buf) const {
> - if (!fetchToPos(address + size - 1)) return -1;
> - memcpy(buf, &Bytes[address + BytesSkipped], size);
> - return 0;
> +uint64_t StreamingMemoryObject::readBytes(uint8_t *Buf, uint64_t Size,
> + uint64_t Address) const {
> + fetchToPos(Address + Size - 1);
> + uint64_t BufferSize = Bytes.size() - BytesSkipped;
> + if (Address >= BufferSize)
> + return 0;
> +
> + uint64_t End = Address + Size;
> + if (End > BufferSize)
> + End = BufferSize;
> + Size = End - Address;
> + assert(Size >= 0);
/home/admin/llvm-project/llvm/lib/Support/StreamingMemoryObject.cpp:100:18:
warning: comparison of unsigned expression >= 0 is always true
[-Wtype-limits]
Jay.
More information about the llvm-commits
mailing list