<div dir="ltr"><br><br><div class="gmail_quote">On Wed Feb 11 2015 at 2:22:51 PM Zachary Turner <<a href="mailto:zturner@google.com">zturner@google.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote">On Wed Feb 11 2015 at 2:04:38 PM Greg Clayton <<a href="mailto:gclayton@apple.com" target="_blank">gclayton@apple.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote></div></div><div dir="ltr"><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
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.<br></blockquote></div></div><div dir="ltr"><div class="gmail_quote"><div>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.</div><div><br></div><div>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.</div></div></div></blockquote><div><br></div><div>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. </div></div></div>