<div dir="ltr">On Mon, Jul 1, 2013 at 4:54 PM, Michael Gottesman <span dir="ltr"><<a href="mailto:mgottesman@apple.com" target="_blank">mgottesman@apple.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: mgottesman<br>
Date: Mon Jul 1 18:54:08 2013<br>
New Revision: 185397<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=185397&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=185397&view=rev</a><br>
Log:<br>
[APFloat] Ensure that we can properly parse strings that do not have null terminators.<br>
<br>
rdar://14323230<br>
<br>
Modified:<br>
llvm/trunk/lib/Support/APFloat.cpp<br>
llvm/trunk/unittests/ADT/APFloatTest.cpp<br>
<br>
Modified: llvm/trunk/lib/Support/APFloat.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APFloat.cpp?rev=185397&r1=185396&r2=185397&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APFloat.cpp?rev=185397&r1=185396&r2=185397&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/APFloat.cpp (original)<br>
+++ llvm/trunk/lib/Support/APFloat.cpp Mon Jul 1 18:54:08 2013<br>
@@ -2481,7 +2481,14 @@ APFloat::convertFromDecimalString(String<br>
42039/12655 < L < 28738/8651 [ numerator <= 65536 ]<br>
*/<br>
<br>
- if (decDigitValue(*D.firstSigDigit) >= 10U) {<br>
+ // Test if we have a zero number allowing for strings with no null terminators<br>
+ // and zero decimals with non-zero exponents.<br>
+ //<br>
+ // We computed firstSigDigit by ignoring all zeros and dots. Thus if<br>
+ // D->firstSigDigit equals str.end(), every digit must be a zero and there can<br>
+ // be at most one dot. On the other hand, if we have a zero with a non-zero<br>
+ // exponent, then we know that D.firstSigDigit will be non-numeric.<br>
+ if (decDigitValue(*D.firstSigDigit) >= 10U || D.firstSigDigit == str.end()) {<br>
category = fcZero;<br>
fs = opOK;<br>
<br></blockquote><div><br></div><div>Aren't these checks in the wrong order? It would be nice to avoid dereferencing str.end().</div><div><br></div><div>-Eli</div></div></div></div>