Return zero when we don't support the byte size. Previously is we were asked to read 3, 5, 6, or 7 byte integers, we would set the error, but still return that we read that number of bytes without populating the scalar.

llvm-svn: 180896
This commit is contained in:
Greg Clayton 2013-05-01 23:41:30 +00:00
parent 16f45ca6ba
commit 7060f8976c
1 changed files with 14 additions and 20 deletions

View File

@ -2644,32 +2644,26 @@ Process::ReadScalarIntegerFromMemory (addr_t addr,
Scalar &scalar,
Error &error)
{
uint64_t uval;
if (byte_size <= sizeof(uval))
uint64_t uval = 0;
if (byte_size == 0)
{
size_t bytes_read = ReadMemory (addr, &uval, byte_size, error);
error.SetErrorString ("byte size is zero");
}
else if (byte_size & (byte_size - 1))
{
error.SetErrorStringWithFormat ("byte size %u is not a power of 2", byte_size);
}
else if (byte_size <= sizeof(uval))
{
const size_t bytes_read = ReadMemory (addr, &uval, byte_size, error);
if (bytes_read == byte_size)
{
DataExtractor data (&uval, sizeof(uval), GetByteOrder(), GetAddressByteSize());
lldb::offset_t offset = 0;
if (byte_size == 0)
{
error.SetErrorString ("byte size is zero");
}
else if (byte_size & (byte_size - 1))
{
error.SetErrorStringWithFormat ("byte size %u is not a power of 2", byte_size);
}
if (byte_size <= 4)
scalar = data.GetMaxU32 (&offset, byte_size);
else
{
if (byte_size <= 4)
scalar = data.GetMaxU32 (&offset, byte_size);
else
scalar = data.GetMaxU64 (&offset, byte_size);
}
scalar = data.GetMaxU64 (&offset, byte_size);
if (is_signed)
scalar.SignExtend(byte_size * 8);
return bytes_read;