[jsword-devel] [JIRA] Created: (JS-210) Numeric overflow in Job.incrementWorkDone

Martin Denham (JIRA) jira at crosswire.org
Sat Mar 3 14:47:03 MST 2012


Numeric overflow in Job.incrementWorkDone
-----------------------------------------

                 Key: JS-210
                 URL: http://www.crosswire.org/bugs/browse/JS-210
             Project: JSword
          Issue Type: Bug
          Components: o.c.common.util
            Reporter: Martin Denham
            Assignee: DM Smith


There is an int related numeric overflow in Job.incrementWorkDone that is fixed by forcing to Long.  It does not cause an exception but pc done suddenly becomes negative half way through a download.

Here is the code:
        percent = 100 * workUnits / totalUnits;

I was downloading a large map and the following sort of numbers were occurring.  You will see the number printed is negative:
	int workUnits =33418592;
	int totunits=33746725;
	System.out.println(100*workUnits/totunits);

One easy fix is to use 100L instead of 100 and then recasting back to an int after:
        percent = (int)(100L * workUnits / totalUnits);



--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jsword-devel mailing list