<br><br><div class="gmail_quote">On Sat, Aug 15, 2009 at 4:02 AM, Dan Gohman <span dir="ltr"><<a href="mailto:gohman@apple.com">gohman@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
-/// ComputeColumn - Examine the current output and figure out which<br>
+/// CountColumns - Examine the given char sequence and figure out which<br>
 /// column we end up in after output.<br>
 ///<br>
-void formatted_raw_ostream::ComputeColumn() {<br>
+static unsigned CountColumns(unsigned Column, const char *Ptr, size_t Size) {<br>
   // Keep track of the current column by scanning the string for<br>
   // special characters<br>
<br>
-  // The buffer may have been allocated underneath us.<br>
-  if (Scanned == 0 && GetNumBytesInBuffer() != 0) {<br>
-    Scanned = begin();<br>
-  }<br>
-<br>
-  while (Scanned != end()) {<br>
-    ++ColumnScanned;<br>
-    if (*Scanned == '\n' || *Scanned == '\r')<br>
-      ColumnScanned = 0;<br>
-    else if (*Scanned == '\t')<br>
+  for (const char *End = Ptr + Size; Ptr != End; ++Ptr) {<br>
+    ++Column;<br>
+    if (*Ptr == '\n' || *Ptr == '\r')<br>
+      Column = 0;<br>
+    else if (*Ptr == '\t')<br>
       // Assumes tab stop = 8 characters.<br>
-      ColumnScanned += (8 - (ColumnScanned & 0x7)) & 0x7;<br>
-    ++Scanned;<br>
+      Column += (8 - (Column & 0x7)) & 0x7;<br>
   }<br>
+<br>
+  return Column;<br>
+}</blockquote><div><br>Hi all, <br></div></div><br>Is it legal to output Instruction or any Value using formatted stream like this:<br>Out << *Instr;<br><br>I was using it to print commented LLVM instructions to my assembly to check if I'm translating instructions correctly, but since the change above I get segfault after running my backend.<br>
<br>Changing line:<br>for (const char *End = Ptr + Size; Ptr != End; ++Ptr) {<br><br>to:<br>
+  for (const char *End = Ptr + Size; Ptr < End; ++Ptr) {<br><br>helps. Is it bug or I just should not use it that way?<br><br>Thanks,<br>Artur<br>