Fixed Process::ReadScalarIntegerFromMemory()
to report proper errors when the size is not
correct.
<rdar://problem/13784456>
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@180888 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Target/Process.cpp b/source/Target/Process.cpp
index f60adca..95abb79 100644
--- a/source/Target/Process.cpp
+++ b/source/Target/Process.cpp
@@ -2653,10 +2653,22 @@
{
DataExtractor data (&uval, sizeof(uval), GetByteOrder(), GetAddressByteSize());
lldb::offset_t offset = 0;
- if (byte_size <= 4)
- scalar = data.GetMaxU32 (&offset, byte_size);
+
+ 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);
+ }
else
- scalar = data.GetMaxU64 (&offset, byte_size);
+ {
+ if (byte_size <= 4)
+ scalar = data.GetMaxU32 (&offset, byte_size);
+ else
+ scalar = data.GetMaxU64 (&offset, byte_size);
+ }
if (is_signed)
scalar.SignExtend(byte_size * 8);