<div dir="ltr">I have followed the discussion about this on lldb-dev a week ago (which did not seem to have reached a definitive conclusion), but I must say I agree with Greg's interpretation:<div><br><div>When I see a "const char *", I immediately assume it is null terminated (unless accompanied by a size argument, or something like that). I think we agree on that.</div><div><br></div><div>However, this is not the case for llvm::StringRef - it already contains the length information, so I cease to care about null termination. In fact, the entire purpose of the StringRef function (in my opinion) is to enable easy processing of non-null terminated strings. You often need to take a substring of a large string and pass it to some function as a parameter. For example I can write "void foo(StringRef x) { x = x.trim(); bar(x); }".</div><div>Without StringRef I would either need to copy the string to ensure null termination or modify the receiver to take a pointer+length combo. Now if we demand that the StringRef contents be a null terminated string, we're back at square one - we again need to copy, only this time we end up passing the length parameter anyway. Then, I see no added value in using StringRef over const char * (ok, you have the length precomputed, which can save a couple of strlen()s, but that's not a big deal).</div></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 23 February 2015 at 16:01, 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">No we don't.  A const char* is not guaranteed to be null terminated either.  Its up to you to make sure you pass it a null terminated string.  Same applies here.<br><div class="gmail_quote"><div><div class="h5">On Mon, Feb 23, 2015 at 1:41 AM Pavel Labath <<a href="mailto:labath@google.com" target="_blank">labath@google.com</a>> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On 20 February 2015 at 19:46, Enrico Granata <span dir="ltr"><<a href="mailto:egranata@apple.com" target="_blank">egranata@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="overflow:hidden">+Error<br>
+OptionValueLanguage::SetValueFromString (llvm::StringRef value, VarSetOperationType op)<br>
+{<br>
+    Error error;<br>
+    switch (op)<br>
+    {<br>
+    case eVarSetOperationClear:<br>
+        Clear();<br>
+        break;<br>
+<br>
+    case eVarSetOperationReplace:<br>
+    case eVarSetOperationAssign:<br>
+        {<br>
+            LanguageType new_type = LanguageRuntime::GetLanguageTypeFromString(value.data());</div></blockquote></div><br></div></div><div dir="ltr"><div class="gmail_extra">Hi,</div><div class="gmail_extra"><br></div><div class="gmail_extra">llvm::StringRef::data() is not guaranteed to return a null terminated string. We would need to call value.str().c_str() here, or (even better) fix the receiver to operate on llvm::StringRef as well.</div><div class="gmail_extra"><br></div><div class="gmail_extra">cheers,</div><div class="gmail_extra">pl</div></div></div></div><span class="">
______________________________<u></u>_________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@cs.uiuc.edu" target="_blank">lldb-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/lldb-commits</a><br>
</span></blockquote></div>
</blockquote></div><br></div>