<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">r228613<br class=""><div><blockquote type="cite" class=""><div class="">On Feb 9, 2015, at 1:23 PM, Ben Langmuir <<a href="mailto:blangmuir@apple.com" class="">blangmuir@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 9, 2015, at 1:03 PM, Chandler Carruth <<a href="mailto:chandlerc@google.com" class="">chandlerc@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Feb 9, 2015 at 12:13 PM, Ben Langmuir <span dir="ltr" class=""><<a href="mailto:blangmuir@apple.com" target="_blank" class="">blangmuir@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div id=":3ik" class="a3s" style="overflow:hidden">Date: Mon Feb  9 14:13:11 2015<br class="">
New Revision: 228601<br class="">
<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=228601&view=rev" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=228601&view=rev</a><br class="">
Log:<br class="">
Update r228592 for when gethostname() returns an error<br class="">
<br class="">
If gethostname() is not successful, just skip adding the hostname to the<br class="">
module hash.  And don't bother setting hostname[255] = 0, since if<br class="">
gethostname() is successful, it will be null-terminated already (and if<br class="">
it's not successful we don't read the string now.<br class=""></div></blockquote></div><br class="">Sadly, I think this still isn't enough to be pedantically correct.</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">The relevant specs allow for a gethostname to not return an error even when truncation occurs, and do not require null termination when truncation occurs.</div></div></div></blockquote><div class=""><br class=""></div><div class="">Yikes.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"> Linux (glibc at least) returns an error and set errno to either EINVAL or ENAMETOOLONG. SUS and POSIX don't really seem to allow this to fail…</div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><br class=""></div><div class="gmail_extra">I think the "best" approach here is:</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">if (gethostname(...) == 0 || errno == ENAMETOOLONG || errno == EINVAL) {<br class="">  hostname[sizeof(hostname) - 1] = 0;</div><div class="gmail_extra">  hash_combine(...);</div><div class="gmail_extra">}</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">But I'm fine if you refuse to handle ENAMETOOLONG or EINVAL, and just null terminate the thing forcibly and only use it when it returns a non-error. I don't believe it is possible for you to reach the error on Linux because the kernel doesn't provide 256 bytes for the hostname anyways. ;]</div></div>
</div></blockquote><br class=""></div><div class="">Okay, I’ll forcibly null-terminate it, but won’t allow the errors.  Thanks for helping me figure this out :-)</div><div class=""><br class=""></div><div class="">Ben</div></div>_______________________________________________<br class="">cfe-commits mailing list<br class=""><a href="mailto:cfe-commits@cs.uiuc.edu" class="">cfe-commits@cs.uiuc.edu</a><br class="">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits<br class=""></div></blockquote></div><br class=""></body></html>