[llvm-commits] [llvm] r120600 - in /llvm/trunk: include/llvm/ADT/Twine.h lib/Support/Twine.cpp unittests/ADT/TwineTest.cpp
Frits van Bommel
fvbommel at gmail.com
Wed Dec 1 12:52:54 PST 2010
On Wed, Dec 1, 2010 at 9:37 PM, Michael J. Spencer
<bigcheesegs at gmail.com> wrote:
> Log:
> Support/ADT/Twine: Add toNullTerminatedStringRef.
> +StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl<char> &Out) const {
> + if (isSingleStringRef()) {
> + StringRef sr = getSingleStringRef();
> + if (*(sr.begin() + sr.size()) == 0)
This is undefined behavior if the StringRef is at the end of whatever
memory allocation it's in.
For instance, it might for instance have been constructed from a
std::string, which doesn't need to null-terminate its data unless
c_str() is called, or it might have been constructed with the pointer
+ length constructor.
> + return sr;
> + }
> + toVector(Out);
> + Out.push_back(0);
> + Out.pop_back();
> + return StringRef(Out.data(), Out.size());
> +}
More information about the llvm-commits
mailing list