On Wed Feb 11 2015 at 2:22:51 PM Zachary Turner <ztur...@google.com> wrote:
> On Wed Feb 11 2015 at 2:04:38 PM Greg Clayton <gclay...@apple.com> wrote: > >> > >> But that isn't what is currently meant by _any_ of the functions that >> take a "const char *" with no length parameter, so it means that any switch >> to using llvm::StringRef requires we use ".str().c_str()" which I would >> like to avoid. >> > I don't see why this is necessary. Just because StringRef supports > non-null terminated strings doesn't mean we have to use non null terminated > strings with it. declaring a SmallString<> and passing by SmallVectorImpl& > supports null terminating strings. You push_back(0) and then pop_back() > before returning. This is no different from what we're already doing by > setting foo[n] = '\0' except that it's safer since there's no chance of a > buffer overrun. > > We are already taking care to make sure all of our const char*s are > properly null terminated. Therefore when they are passed to functions that > accept a StringRef, they will continue to be null terminated. > Also, if we move away from stack allocated buffers towards std::string, then the problem is also solved for us, because std::string::c_str() always returns a null terminated string, so creating a StringRef out of it is fine. StringRef is really just exactly what we already have, but with member functions on it to automatically perform common operations.
_______________________________________________ lldb-dev mailing list lldb-dev@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev