ktorrent ran fine when I was using openbsd-4.2.  I then switched to
-current and ktorrent-2.2.5 started having problems.  Transfer speeds
continually increased on the interface and it eventually used too much
memory and crashed.  The problem has to do with a screwy calculation
with implicit casts.  I also tried building ktorrent-2.1.4 (used in
openbsd-4.2) from source and found the same problem.

Here's the change I made that's going into ktorrent svn:

--- libktorrent/util/functions.cpp      Sun Jan 27 06:06:02 2008
+++ libktorrent/util/functions.cpp      Fri Mar  7 18:58:48 2008
@@ -178,7 +178,8 @@ namespace bt
        {
                struct timeval tv;
                gettimeofday(&tv,0);
-               global_time_stamp = (Uint64)(tv.tv_sec * 1000 + tv.tv_usec * 
0.001);
+               global_time_stamp = static_cast<Uint64>(tv.tv_sec) * 1000 +
+                   tv.tv_usec / 1000;
                return global_time_stamp;
        }
        

(that's a tab character on the last line)  The problems above are 1)
multiplication of seconds and 1000 causes overflow into the sign bit,
2) multiplying by a double to divide by 1000 is completely
unnecessary, and causes 3) the addition is done using doubles,
creating a negative result, which casted to uint64 produces 0.  I
don't know what changed between OpenBSD-4.2 and -current that might
affect this, but it's clear something did.

Reply via email to