[llvm-commits] [llvm] r79065 - /llvm/trunk/lib/Support/FormattedStream.cpp

Artur Pietrek pietreka at gmail.com
Tue Aug 18 03:27:00 PDT 2009


On Mon, Aug 17, 2009 at 6:30 PM, Dan Gohman <gohman at apple.com> wrote:

>
>
> On Aug 17, 2009, at 2:42 AM, Artur Pietrek <pietreka at gmail.com> wrote:
>
>
>
> On Sat, Aug 15, 2009 at 4:02 AM, Dan Gohman < <gohman at apple.com>
> gohman at apple.com> wrote:
>
>>
>> -/// ComputeColumn - Examine the current output and figure out which
>> +/// CountColumns - Examine the given char sequence and figure out which
>>  /// column we end up in after output.
>>  ///
>> -void formatted_raw_ostream::ComputeColumn() {
>> +static unsigned CountColumns(unsigned Column, const char *Ptr, size_t
>> Size) {
>>   // Keep track of the current column by scanning the string for
>>   // special characters
>>
>> -  // The buffer may have been allocated underneath us.
>> -  if (Scanned == 0 && GetNumBytesInBuffer() != 0) {
>> -    Scanned = begin();
>> -  }
>> -
>> -  while (Scanned != end()) {
>> -    ++ColumnScanned;
>> -    if (*Scanned == '\n' || *Scanned == '\r')
>> -      ColumnScanned = 0;
>> -    else if (*Scanned == '\t')
>> +  for (const char *End = Ptr + Size; Ptr != End; ++Ptr) {
>> +    ++Column;
>> +    if (*Ptr == '\n' || *Ptr == '\r')
>> +      Column = 0;
>> +    else if (*Ptr == '\t')
>>       // Assumes tab stop = 8 characters.
>> -      ColumnScanned += (8 - (ColumnScanned & 0x7)) & 0x7;
>> -    ++Scanned;
>> +      Column += (8 - (Column & 0x7)) & 0x7;
>>   }
>> +
>> +  return Column;
>> +}
>
>
> Hi all,
>
> Is it legal to output Instruction or any Value using formatted stream like
> this:
> Out << *Instr;
>
>
> Yes, that's fine.  Fairly common, in fact.
>
>
> 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.
>
> Changing line:
> for (const char *End = Ptr + Size; Ptr != End; ++Ptr) {
>
> to:
> +  for (const char *End = Ptr + Size; Ptr < End; ++Ptr) {
>
> helps. Is it bug or I just should not use it that way?
>
>
> The change shouldn't be necessary.  It sounds like there's a bug.  Is Ptr
> pointing to a valid string when this happens?
>

Ptr is not a valid string and Size is 0x1000.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20090818/60bc6c0c/attachment.html>


More information about the llvm-commits mailing list