Menu

#1999 Possible integer overflow in getTotalUSec

Code_Cleanup
closed-fixed
5
2010-09-15
2010-06-28
No

Bug: Result of integer multiplication cast to long
Pattern id: ICAST_INTEGER_MULTIPLY_CAST_TO_LONG, type: ICAST, category: STYLE

This code performs integer multiply and then converts the result to a long, as in:

long convertDaysToMilliseconds\(int days\) \{ return 1000\*3600\*24\*days; \}

If the multiplication is done using long arithmetic, you can avoid the possibility that the result will overflow. For example, you could fix the above code to:

long convertDaysToMilliseconds\(int days\) \{ return 1000L\*3600\*24\*days; \}

Discussion

  • Dave Blaschke

    Dave Blaschke - 2010-06-28

    Fixing this eliminates 1 FindBugs issue

     
  • Dave Blaschke

    Dave Blaschke - 2010-06-30
    • status: open --> open-accepted
     
  • Dave Blaschke

    Dave Blaschke - 2010-06-30

    Patch sent for community review. During a 2 week period any
    exploiter may comment on the patch, request changes or turn it
    down completely (with good reason). For the time being the patch is part of the "Experimental" branch in CVS.

     
  • Dave Blaschke

    Dave Blaschke - 2010-06-30
    • status: open-accepted --> open-fixed
     
  • Dave Blaschke

    Dave Blaschke - 2010-07-28

    Patch against HEAD

     
  • Dave Blaschke

    Dave Blaschke - 2010-07-28

    The community review has completed and we received no substantial critisism. Therefore the patch has been approved and merged into the "HEAD" branch. The next release will pick it up.

     
  • Dave Blaschke

    Dave Blaschke - 2010-07-28
    • status: open-fixed --> pending-fixed
     
  • Dave Blaschke

    Dave Blaschke - 2010-09-15
    • status: pending-fixed --> closed-fixed
     
  • Dave Blaschke

    Dave Blaschke - 2010-09-15

    The patch was picked up by release 2.1.6 and will therefore be closed.

     

Log in to post a comment.