diff options
author | Scott Linder <scott@scottlinder.com> | 2018-08-23 02:51:09 +0000 |
---|---|---|
committer | Scott Linder <scott@scottlinder.com> | 2018-08-23 02:51:09 +0000 |
commit | a755f4d1a076b3fefd46be8cd398aeaa7d60beb9 (patch) | |
tree | bfb1986fea1054b7f6dbbf39f903c03299e66fcd /llvm/lib/BinaryFormat/MsgPackWriter.cpp | |
parent | 560e1ed3379e7cb5c65e5474000245f7dcde5266 (diff) | |
download | bcm5719-llvm-a755f4d1a076b3fefd46be8cd398aeaa7d60beb9.tar.gz bcm5719-llvm-a755f4d1a076b3fefd46be8cd398aeaa7d60beb9.zip |
Fix undefined behavior in r340457
llvm-svn: 340507
Diffstat (limited to 'llvm/lib/BinaryFormat/MsgPackWriter.cpp')
-rw-r--r-- | llvm/lib/BinaryFormat/MsgPackWriter.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/llvm/lib/BinaryFormat/MsgPackWriter.cpp b/llvm/lib/BinaryFormat/MsgPackWriter.cpp index 32460d56238..d024bb0fcdb 100644 --- a/llvm/lib/BinaryFormat/MsgPackWriter.cpp +++ b/llvm/lib/BinaryFormat/MsgPackWriter.cpp @@ -88,10 +88,11 @@ void Writer::write(uint64_t u) { void Writer::write(double d) { // If no loss of precision, encode as a Float32. - float f = static_cast<float>(d); - if (static_cast<double>(f) == d) { + double a = std::fabs(d); + if (a >= std::numeric_limits<float>::min() && + a <= std::numeric_limits<float>::max()) { EW.write(FirstByte::Float32); - EW.write(f); + EW.write(static_cast<float>(d)); } else { EW.write(FirstByte::Float64); EW.write(d); |