From d58d7dedaf331ff59d76bc235d34683f5585c12e Mon Sep 17 00:00:00 2001 From: Steve Gribble Date: Tue, 5 Jan 2010 15:31:42 -0800 Subject: [PATCH] Fix float parsing bug that manifests on Qt4.6 and later. This file relies on Qt's QDataStream to handle the parsing of primitive C types from Computrainer .3dp files, including floats. In Qt4.5 and earlier, Qt defaulted to 32 bit floats. In Qt4.6 and later, Qt started using 64 bit floats by default. As a side-effect, parsing broke on Qt4.6, leading to a crash when importing or using .3dp files. This patch fixes the issue by using QDataStream's "setVersion()" method to tell Qt to use the Qt4.0 serialization format for the QDataStream used in this file. This patch does not affect any other files. This patch should make the formatting assumptions both backwards and forwards compatible. --- src/Computrainer3dpFile.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Computrainer3dpFile.cpp b/src/Computrainer3dpFile.cpp index 67dc1eedd..18679dcde 100644 --- a/src/Computrainer3dpFile.cpp +++ b/src/Computrainer3dpFile.cpp @@ -60,6 +60,12 @@ RideFile *Computrainer3dpFileReader::openRideFile(QFile & file, } RideFile *rideFile = new RideFile(); QDataStream is(&file); + + // Note that QT4.6 and above default to 64 bit floats. For + // backwards and forwards compatibility, we'll freeze the stream + // version we use for parsing at 4.0, and then add in LittleEndian + // number format, which is what Computrainer3dp has. + is.setVersion(QDataStream::Qt_4_0); is.setByteOrder(QDataStream::LittleEndian); // start parsing the header