Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object reference for static methods in Java #104

Closed
mgudemann opened this issue Jun 6, 2016 · 4 comments
Closed

object reference for static methods in Java #104

mgudemann opened this issue Jun 6, 2016 · 4 comments

Comments

@mgudemann
Copy link
Contributor

When checking for division by zero, the following shows different results when analyzing the static method f (passes the verification) and g (fails verification), although non-deterministic choice for the input integer should allow for a = -1 in the first case, too.

public class StaticMethod { 
  static public void f(int a, int b) {
    int c = b/(a+1);
  }
  static public void g(int a, int b) {
    int c = a/(b+1);
  }
}

The problem seems to be that the first parameter that is passed to the static method is the result of a malloc, i.e., the memory allocated for a StaticMethod object instance. Whereas, in the function it is treated as a NONDET(int).

        // 0 no location
        __CPROVER_initialize();
        // 1 no location
        tmp_struct_init$1 = MALLOC(struct StaticMethod { struct java.lang.Object @java.lang.Object; }, 4);
        // 2 no location
        tmp_struct_init$1->@java.lang.Object.@class_identifier = "StaticMethod";
        // 3 no location
        StaticMethod.g:(II)V(tmp_struct_init$1, NONDET(int));
        // 4 no location
        END_FUNCTION
StaticMethod.f() /* java::StaticMethod.f:(II)V */
        // 7 file StaticMethod.java line 4
        ASSERT !(arg0i == -1) // division by zero in arg1i / (arg0i + 1)
        // 8 file StaticMethod.java line 4
        local2i = arg1i / (arg0i + 1);
        // 9 no location
        END_FUNCTION
kroening pushed a commit that referenced this issue Jun 6, 2016
@kroening
Copy link
Member

kroening commented Jun 6, 2016

I have turned this into regression/cbmc-java/static_method1

@kroening
Copy link
Member

kroening commented Jun 7, 2016

Can you take another look? Both f and g now fail verification.

@mgudemann
Copy link
Contributor Author

Yes, both fail now with div-by-zero checks. The name for methods for --function must now be without preceeding java::, is this intended? --show-goto-functions shows the name with this prefix.

@mgudemann
Copy link
Contributor Author

ok, I just saw the commit message for 5b67c01 for the prefix. For me this issue is resolved.

smowton pushed a commit to smowton/cbmc that referenced this issue May 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants