[cfe-commits] r44339 - in /cfe/trunk: Lex/LiteralSupport.cpp include/clang/Lex/LiteralSupport.h
Neil Booth
neil at daikokuya.co.uk
Tue Nov 27 05:14:31 PST 2007
Hi Ted,
Ted Kremenek wrote:-
> llvm::APFloat NumericLiteralParser::
> -GetFloatValue(const llvm::fltSemantics &Format) {
> +GetFloatValue(const llvm::fltSemantics &Format, bool* isExact) {
> + using llvm::APFloat;
> +
> char floatChars[256];
> strncpy(floatChars, ThisTokBegin, ThisTokEnd-ThisTokBegin);
> floatChars[ThisTokEnd-ThisTokBegin] = '\0';
I realize you didn't write it but that local buffer overflow
has to go :)
If ThisTokEnd points to a valid character that cannot continue
the literal, then pass ThisTokBegin and be done with it - APFloat
parses until the first character that is syntactically incorrect;
it assumes the caller has verified the syntax. In other words
\0 is just one example of a suitable terminator; almost anything
outside [0-9.eE+-pP] will do.
> +#if 1
> + APFloat V (Format, APFloat::fcZero, false);
> +
> + APFloat::opStatus status;
> + status = V.convertFromString(floatChars,APFloat::rmTowardZero);
> +
> + if (isExact)
> + *isExact = status == APFloat::opOK;
> +
> + return V;
I think in general we should be rounding to nearest, not zero.
Neil.
More information about the cfe-commits
mailing list