Menu

#553 Potential problems moving to 64 bits

open
nobody
None
5
2014-09-08
2010-10-17
No

I am interested in two problems that occur frequently when moving code to 64 bits:

public class Test {

public static void main( String arg[] ) {
    long a = <some value>;

    int i = 0;

    i += a;

    for( i = 0; i < a; i++ ) System.err.println( i );

}

}

In this class, two problems arise: i+=a could cause an overflow, but will give no error or warning. Then the loop will exit when i becomes negative (instead when i == a).

Would be PMD able to spot such potential bugs with proper rules? thanks!

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.