[cfe-commits] r154981 - in /cfe/trunk: lib/Frontend/TextDiagnostic.cpp test/Misc/wnull-character.cpp

Nico Weber thakis at chromium.org
Thu Apr 26 14:37:16 PDT 2012


Hi Seth,

On Tue, Apr 17, 2012 at 7:44 PM, Seth Cantrell <seth.cantrell at gmail.com> wrote:
> Author: socantre
> Date: Tue Apr 17 21:44:48 2012
> New Revision: 154981
>
> URL: http://llvm.org/viewvc/llvm-project?rev=154981&view=rev
> Log:
> fix display of source lines with null characters
>
> Added:
>    cfe/trunk/test/Misc/wnull-character.cpp
> Modified:
>    cfe/trunk/lib/Frontend/TextDiagnostic.cpp
>
> Modified: cfe/trunk/lib/Frontend/TextDiagnostic.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnostic.cpp?rev=154981&r1=154980&r2=154981&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/TextDiagnostic.cpp (original)
> +++ cfe/trunk/lib/Frontend/TextDiagnostic.cpp Tue Apr 17 21:44:48 2012
> @@ -839,10 +839,13 @@
>
>   // Get information about the buffer it points into.
>   bool Invalid = false;
> -  const char *BufStart = SM.getBufferData(FID, &Invalid).data();
> +  StringRef BufData = SM.getBufferData(FID, &Invalid);
>   if (Invalid)
>     return;
>
> +  const char *BufStart = BufData.data();
> +  const char *BufEnd = BufStart + BufData.size();
> +
>   unsigned LineNo = SM.getLineNumber(FID, FileOffset);
>   unsigned ColNo = SM.getColumnNumber(FID, FileOffset);
>   unsigned CaretEndColNo
> @@ -856,7 +859,7 @@
>   // Compute the line end.  Scan forward from the error position to the end of
>   // the line.
>   const char *LineEnd = TokPtr;
> -  while (*LineEnd != '\n' && *LineEnd != '\r' && *LineEnd != '\0')
> +  while (*LineEnd != '\n' && *LineEnd != '\r' && LineEnd!=BufEnd)

this caused PR12674. I can't think of a good fix, so I'll revert this,
with a test that shows what went wrong. Note that even with this CL,
strings with embedded newline characters weren't printed correctly.

Nico

>     ++LineEnd;
>
>   // FIXME: This shouldn't be necessary, but the CaretEndColNo can extend past
>
> Added: cfe/trunk/test/Misc/wnull-character.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/wnull-character.cpp?rev=154981&view=auto
> ==============================================================================
> Binary files cfe/trunk/test/Misc/wnull-character.cpp (added) and cfe/trunk/test/Misc/wnull-character.cpp Tue Apr 17 21:44:48 2012 differ
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list