Uploaded image for project: 'JSword'
  1. JSword
  2. JS-210

Numeric overflow in Job.incrementWorkDone

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.7
    • Component/s: o.c.common.util
    • Labels:
      None

      Description

      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);

        Attachments

          Activity

            People

            • Assignee:
              dmsmith DM Smith
              Reporter:
              mjdenham Martin Denham
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: