Skip to content

Commit a755f4d

Browse files
committedAug 23, 2018
Fix undefined behavior in r340457
llvm-svn: 340507
1 parent 560e1ed commit a755f4d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed
 

‎llvm/lib/BinaryFormat/MsgPackWriter.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ void Writer::write(uint64_t u) {
8888

8989
void Writer::write(double d) {
9090
// If no loss of precision, encode as a Float32.
91-
float f = static_cast<float>(d);
92-
if (static_cast<double>(f) == d) {
91+
double a = std::fabs(d);
92+
if (a >= std::numeric_limits<float>::min() &&
93+
a <= std::numeric_limits<float>::max()) {
9394
EW.write(FirstByte::Float32);
94-
EW.write(f);
95+
EW.write(static_cast<float>(d));
9596
} else {
9697
EW.write(FirstByte::Float64);
9798
EW.write(d);

0 commit comments

Comments
 (0)
Please sign in to comment.