On Sat, Jul 19, 2008 at 01:10:27PM -0700, Russ Allbery wrote: > If temp is actually a float and sizeof(float) != sizeof(double), I believe > this code is not safe. It takes the space pointed to by temp and blindly > interprets it as a double, meaning that if sizeof(float) < sizeof(double), > you're storing part of the result in adjacent memory.
Right. > I think you have to change the type of temp from a qreal to a double for > the code to be safe (and then check the adjacent code to make sure that > doesn't break anything else). temp stores the integer part of qreal's variables start_frac, end_frac (note cast to int). I think the following code should be safe for all arches: maybe should I encapsulate it in a kind of #define like my previous example? --- qbittorrent-1.1.0beta3.orig/src/realprogressbarthread.cpp +++ qbittorrent-1.1.0beta3/src/realprogressbarthread.cpp @@ -141,7 +141,8 @@ if (end > array.size()) end = array.size(); int start_int, end_int; - qreal temp, start_frac, end_frac; + qreal start_frac, end_frac; + double temp; start_frac = modf(start, &temp); start_int = (int) temp; end_frac = modf(end, &temp); Thanks, Cristian
signature.asc
Description: Digital signature