This is an archive of the discontinued LLVM Phabricator instance.

[SourceManager] Support buffers that are not null-terminated
AbandonedPublic

Authored by loladiro on Sep 14 2015, 11:23 AM.

Details

Reviewers
bkramer
Summary

I feed custom buffers to clang, and since the buffers store an explicit length, I did not think to null-terminate them.
However, this causes clang to run out-of-bounds in certain situations in ComputeLineNumbers. Since under certain
situations ComputeLineNumbers does look at the given bounds, I figured the proper solution was to always check the
buffer for EOF. Please let me know if I missed something and this was intended.

Diff Detail

Repository
rL LLVM

Event Timeline

loladiro updated this revision to Diff 34708.Sep 14 2015, 11:23 AM
loladiro retitled this revision from to [SourceManager] Support buffers that are not null-terminated.
loladiro updated this object.
loladiro added a reviewer: bkramer.
loladiro set the repository for this revision to rL LLVM.
loladiro added a subscriber: cfe-commits.

Bump. Could somebody take a look at this?

klimek added a subscriber: klimek.Oct 2 2015, 5:26 AM

Generally, I thought clang often relies on buffers being null terminated to speed up parse times. Usually the MemoryBuffers have an option to guarantee null-terminatedness (and copy if necessary)

Hmm, you're right. And I am actually constructing it in such a way that it's supposed to have it, so I wonder why it ran off the rails here. Will take another look.

loladiro abandoned this revision.Oct 2 2015, 10:43 PM

Oh, I see it checks for the null terminator past the end of the given memory block on construction, but if the memory after changes later this just keeps running. Well, that's quite a trap, but I guess that's what you get for not understanding the API ;).