From 3f936e9094f3a6e4d76791c1eff7ae92f91b61ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Str=C3=B8mme?= Date: Tue, 13 Nov 2012 19:17:17 +0100 Subject: Fixes problem with single precision floats in QDataStream (Windows). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the floating-point behavior in MSVC is set to "precise" (default), assigning nan numbers to a float causes the bit pattern to be altered (only affects 32bit builds). We should therefore not assign the swapped value back to a float and use it. Task-number: QTBUG-25950 Change-Id: I7b6cc4d546e5c8aeafdede749056358b7d639ec7 Reviewed-by: Jędrzej Nowacki --- src/corelib/io/qdatastream.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/corelib/io/qdatastream.cpp') diff --git a/src/corelib/io/qdatastream.cpp b/src/corelib/io/qdatastream.cpp index 9a71f60854..5e5e155534 100644 --- a/src/corelib/io/qdatastream.cpp +++ b/src/corelib/io/qdatastream.cpp @@ -1046,8 +1046,12 @@ QDataStream &QDataStream::operator<<(float f) } x; x.val1 = g; x.val2 = qbswap(x.val2); - g = x.val1; + + if (dev->write((char *)&x.val2, sizeof(float)) != sizeof(float)) + q_status = WriteFailed; + return *this; } + if (dev->write((char *)&g, sizeof(float)) != sizeof(float)) q_status = WriteFailed; return *this; -- cgit v1.2.3