diff options
| author | Enrico Granata <egranata@apple.com> | 2013-10-29 23:04:29 +0000 |
|---|---|---|
| committer | Enrico Granata <egranata@apple.com> | 2013-10-29 23:04:29 +0000 |
| commit | 0947a6e93b4baaeabf3f1943bc8d8e257ca2bb43 (patch) | |
| tree | 5c225170aed12c1dd929e367adc75eb8b52e68a3 | |
| parent | ce20d460e2a96c05ff8a2d5a6d57d6a6ef5a1cfa (diff) | |
| download | bcm5719-llvm-0947a6e93b4baaeabf3f1943bc8d8e257ca2bb43.tar.gz bcm5719-llvm-0947a6e93b4baaeabf3f1943bc8d8e257ca2bb43.zip | |
<rdar://problem/15296388>
Fix a crasher that would occur if one tried to read memory as characters of some size != 1, e.g.
x -f c -s 10 buffer
This commit tries to do the right thing and uses the byte-size as the number of elements, unless both are specified and the number of elements is != 1
In this latter case (e.g. x -f c -s 10 -c 3 buffer) one could multiply the two and read 30 characters, but it seems a stretch in mind reading.
llvm-svn: 193659
| -rw-r--r-- | lldb/source/Commands/CommandObjectMemory.cpp | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index d7e59fb3486..e804b4a6474 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -860,16 +860,28 @@ protected: Format format = m_format_options.GetFormat(); if ( ( (format == eFormatChar) || (format == eFormatCharPrintable) ) - && (item_byte_size != 1) - && (item_count == 1)) + && (item_byte_size != 1)) { - // this turns requests such as - // memory read -fc -s10 -c1 *charPtrPtr - // which make no sense (what is a char of size 10?) - // into a request for fetching 10 chars of size 1 from the same memory location - format = eFormatCharArray; - item_count = item_byte_size; - item_byte_size = 1; + // if a count was not passed, or it is 1 + if (m_format_options.GetCountValue().OptionWasSet() == false || item_count == 1) + { + // this turns requests such as + // memory read -fc -s10 -c1 *charPtrPtr + // which make no sense (what is a char of size 10?) + // into a request for fetching 10 chars of size 1 from the same memory location + format = eFormatCharArray; + item_count = item_byte_size; + item_byte_size = 1; + } + else + { + // here we passed a count, and it was not 1 + // so we have a byte_size and a count + // we could well multiply those, but instead let's just fail + result.AppendErrorWithFormat("reading memory as characters of size %zu is not supported", item_byte_size); + result.SetStatus(eReturnStatusFailed); + return false; + } } assert (output_stream); |

