[LLVMdev] Is append in APFloat broken?
David Blaikie
dblaikie at gmail.com
Tue Jul 24 09:50:17 PDT 2012
On Tue, Jul 24, 2012 at 3:06 AM, Olaf Krzikalla
<Olaf.Krzikalla at tu-dresden.de> wrote:
> Hi @llvm,
>
> I stumbled over a strange behavior if a float containing a NaN is printed
> (e.g. in the clang rewriter). The local template method "append" in
> APFloat.cpp deduces the size from the char array, which for "NaN" is 4
> (including the trailing zero). If APFloat::toString is called with a
> SmallString and then SmallString::str() is called, it returns "NaN\0". I
> guess that this is not intended. Maybe it can be fixed by the simple patch
> attached.
Thanks for the diagnosis.
Do you have a test case to go along with this?
The simpler fix seems to be to untemplate this code & have "append"
take a StringRef. We can just rely on the compiler to optimize away
the strlen in StringRef's (const char*) ctor as we do across the rest
of the codebase. That way this won't go awry if append is called with
a large buffer or a string without a nul terminator, etc.
- David
More information about the llvm-dev
mailing list