[Lldb-commits] [PATCH] Fix FileSpec::GetPath to return null-terminated strings
Zachary Turner
zturner at google.com
Thu Feb 26 08:51:24 PST 2015
Hmm yea, I'm not sure why I wrote replace(). SmallString::slice() might be
what you want. It returns a StringRef. As long as your program is only
operating on String objects (StringRef, SmallVectorImpl, std::string), you
never have to worry. But if you pass to a function taking a const char* you
need to make ConstString out of it first so it is internalized
On Thu, Feb 26, 2015 at 8:46 AM Ilia K <ki.stfu at gmail.com> wrote:
> @zturner, one question about SmallString
>
>
> ================
> Comment at: source/Host/macosx/HostInfoMacOSX.mm:137
> @@ -136,3 +136,3 @@
> return false;
> char raw_path[PATH_MAX];
> lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
> ----------------
> clayborg wrote:
> > zturner wrote:
> > > Bonus points if you can get rid of all the c string manipulation in
> this function and write everything in terms of llvm::SmallString<> and
> llvm::StringRef. the basic idea is this:
> > >
> > > 1) Replace the stack buffer with an llvm::SmallString<PATH_MAX>.
> > > 2) use SmallString<>::find() instead of strstr
> > > 3) Construct a StringRef() with an explicit length instead of
> inserting a null terminator
> > > 4) Use SmallString<>::replace() instead of strncpy
> > > 5) use the file_spec.GetDirectory().SetString(StringRef) instead of
> file_spec.GetDirectory().SetCString(const char*)
> > >
> > > The same improvement could be made to the rest of the functions in
> this file.
> > I would prefer to use std::string instead of llvm::SmallString.
> >RE: 4. Use SmallString<>::replace() instead of strncpy
> The replace() is absent. What I can use instead of it?
>
> http://reviews.llvm.org/D7553
>
> EMAIL PREFERENCES
> http://reviews.llvm.org/settings/panel/emailpreferences/
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150226/91089a7d/attachment.html>
More information about the lldb-commits
mailing list