<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 18 Sep 2015, at 08:27, Roland Haas &lt;<a href="mailto:rhaas@aei.mpg.de">rhaas@aei.mpg.de</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hello all,<br><br><blockquote type="cite">Don't use NaN for poison! &nbsp;If you do, then you cannot tell the<br>difference between NaNs generated because of numerical problems, and<br>poison generated due to programming bugs.<br></blockquote>Not true really. There are multiple "nan" values. See eg<br><a href="http://en.cppreference.com/w/c/numeric/math/nan">http://en.cppreference.com/w/c/numeric/math/nan</a> and if you use nan("17")<br>for poison you will be able to tell it apart from the nan that you get<br>out of 1./0 and sqrt(-1.) type errors.<br><br>Attached it is a simple C99 program to demonstrate this. Basically it<br>means that to detect poison you need to use memcmp (which we already do)<br>and that in floating point arithmetic a nan("17") propagates as a<br>nan("17") when combined with other non-NaN numbers but may be wiped when<br>combined with a NaN (which would also wipe a non-NaN poison value though).<br></blockquote><div><br></div>Fascinating. &nbsp;I had no idea that there was more than one NaN value. &nbsp;The wikipedia page &lt;<a href="https://en.wikipedia.org/wiki/NaN">https://en.wikipedia.org/wiki/NaN</a>&gt; explains it is more detail than the cppreference page.</div><div><br></div><div>The conversion from the character representation to the binary representation appears to not be defined by the C/C++ standard, so presumably is left up to the compiler / libc / platform. &nbsp;Also, I suspect that this usage of NaN payloads is not well supported by most analysis software.</div><div><br></div><div>Apart from those concerns, yes, it would be very good to use a specific type of NaN to represent poison.</div><div><br></div><div apple-content-edited="true">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>--&nbsp;</div><div>Ian Hinder</div><div><a href="http://members.aei.mpg.de/ianhin">http://members.aei.mpg.de/ianhin</a></div></div></div></div></div>
</div>
<br></body></html>