r257259 - Make clang::format::reformat work with non 0-terminated strings.
Benjamin Kramer via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 9 08:19:54 PST 2016
On Sat, Jan 9, 2016 at 4:56 PM, Daniel Jasper via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
> Author: djasper
> Date: Sat Jan 9 09:56:57 2016
> New Revision: 257259
>
> URL: http://llvm.org/viewvc/llvm-project?rev=257259&view=rev
> Log:
> Make clang::format::reformat work with non 0-terminated strings.
>
> Modified:
> cfe/trunk/lib/Format/Format.cpp
>
> Modified: cfe/trunk/lib/Format/Format.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=257259&r1=257258&r2=257259&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Format/Format.cpp (original)
> +++ cfe/trunk/lib/Format/Format.cpp Sat Jan 9 09:56:57 2016
> @@ -1902,8 +1902,9 @@ tooling::Replacements reformat(const For
> IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs),
> new DiagnosticOptions);
> SourceManager SourceMgr(Diagnostics, Files);
> - InMemoryFileSystem->addFile(FileName, 0,
> - llvm::MemoryBuffer::getMemBuffer(Code, FileName));
> + InMemoryFileSystem->addFile(
> + FileName, 0, llvm::MemoryBuffer::getMemBuffer(
> + Code, FileName, /*RequiresNullTerminator=*/false));
Hmm, Clang's Lexer depends on the null terminator at EOF. I'd expect
this change to create invalid memory reads (asan) for cases like
formatting "// foo" without a trailing newline.
- Ben
> FileID ID = SourceMgr.createFileID(Files.getFile(FileName), SourceLocation(),
> clang::SrcMgr::C_User);
> SourceLocation StartOfFile = SourceMgr.getLocForStartOfFile(ID);
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list