<div dir="ltr">@zturner @amccarth Thanks, you are right.<br>I think we could use Adrian's solution since the random access operator [] returns both const and non-const references. So, we can get a non-const pointer.<br>I will update the diff.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 6, 2016 at 2:15 PM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">&result[0] is const, you're going to have to const cast it to do that unfortunately.  Regardless though, manual new / delete is almost never the right solution.  For example, the original code could be replaced with <div><br></div><div>```</div><div>std::vector<char> Buffer(FileName.begin(), FileName.end());</div><div>Buffer.push_back(0);</div><div>memcpy(&Buffer[0], FileName.data(), FileName.size());</div><div>PathRemoveFileSpecA(&Buffer[0]<wbr>);</div><div>return std::string(&Buffer[0]);</div><div>```</div><div><br></div><div>and it would be better than manually new'ing and deleting.  Unless you can accept the const_cast (which I'm not convinced we should in this case), the only alternative is stack allocating the buffer.</div><div><br></div><div>BTW, if we could use llvm then this would be a perfect use case for StringRef :)  Oh well</div></div><div class="HOEnZb"><div class="h5"><br><div class="gmail_quote"><div dir="ltr">On Tue, Dec 6, 2016 at 2:03 PM Adrian McCarthy via Phabricator <<a href="mailto:reviews@reviews.llvm.org" target="_blank">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">amccarth added inline comments.<br class="m_-2838234948731999239gmail_msg">
<br class="m_-2838234948731999239gmail_msg">
<br class="m_-2838234948731999239gmail_msg">
================<br class="m_-2838234948731999239gmail_msg">
Comment at: lib/Fuzzer/FuzzerIOWindows.<wbr>cpp:144<br class="m_-2838234948731999239gmail_msg">
 std::string DirName(const std::string &FileName) {<br class="m_-2838234948731999239gmail_msg">
-  assert(0 && "Unimplemented");<br class="m_-2838234948731999239gmail_msg">
+  char *Tmp = new char[FileName.size() + 1];<br class="m_-2838234948731999239gmail_msg">
+  memcpy(Tmp, FileName.c_str(), FileName.size() + 1);<br class="m_-2838234948731999239gmail_msg">
----------------<br class="m_-2838234948731999239gmail_msg">
Instead of managing memory yourself, I would just use another string as the non-const buffer.  PathRemoveFileSpace may replace one of the characters with '\0', so all you have to do is resize the result.<br class="m_-2838234948731999239gmail_msg">
<br class="m_-2838234948731999239gmail_msg">
    std::string result = FileName;<br class="m_-2838234948731999239gmail_msg">
    PathRemoveFileSpecA(&result[0]<wbr>);<br class="m_-2838234948731999239gmail_msg">
    result.resize(std::strlen(<wbr>result.c_str());<br class="m_-2838234948731999239gmail_msg">
    return result;<br class="m_-2838234948731999239gmail_msg">
<br class="m_-2838234948731999239gmail_msg">
<br class="m_-2838234948731999239gmail_msg">
<br class="m_-2838234948731999239gmail_msg">
Repository:<br class="m_-2838234948731999239gmail_msg">
  rL LLVM<br class="m_-2838234948731999239gmail_msg">
<br class="m_-2838234948731999239gmail_msg">
<a href="https://reviews.llvm.org/D27475" rel="noreferrer" class="m_-2838234948731999239gmail_msg" target="_blank">https://reviews.llvm.org/<wbr>D27475</a><br class="m_-2838234948731999239gmail_msg">
<br class="m_-2838234948731999239gmail_msg">
<br class="m_-2838234948731999239gmail_msg">
<br class="m_-2838234948731999239gmail_msg">
</blockquote></div>
</div></div></blockquote></div><br></div>