<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
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp
index d7e59fb..e804b4a 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -860,16 +860,28 @@
         
         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);