Last active
November 21, 2016 23:42
-
-
Save keigoi/1cd60e92d3c1df0f7f59cdc53f7e5ec5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// check this with facebook infer 0.9.4 | |
int main(void) { | |
int arr[] = {1, 1}; | |
int* p = 0; | |
for(int i = 0; i<2; i++) | |
{ | |
if(arr[0] == 2) // always false | |
{ | |
// hello.c:12: error: NULL_DEREFERENCE | |
// pointer p last assigned on line 4 could be null and is dereferenced at line 12, column 7 | |
*p = 42; | |
} | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// check this with facebook infer 0.9.4 | |
public class Hello { | |
public static void main(String[] args) { | |
Object o1 = new Object(); | |
Object o2 = new Object(); | |
Object n = null; | |
Object[] arr = {o1, o1, o1, o1, o1}; | |
for(int i=0; i<arr.length; i++) { | |
if(arr[i].equals(o2)) { | |
n.equals(n); // never reached but reported as an error | |
} | |
} | |
} | |
} | |
/* | |
import java.util.ArrayList; | |
public class Hello { | |
public static void main(String[] args) { | |
Object o1 = new Object(); | |
Object o2 = new Object(); | |
Object n = null; | |
ArrayList<Object> arr = new ArrayList<>(); | |
arr.add(o1); | |
arr.add(o1); | |
arr.add(o1); | |
arr.add(o1); | |
arr.add(o1); | |
for(Object o : arr) { | |
if(o.equals(o2)) { | |
n.equals(n); | |
} | |
} | |
} | |
} | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// check this with facebook infer 0.9.4 | |
public class Hello2 { | |
public static Object f() { | |
// int[] arr = new int[]{1, 1}; // (1) abstraction is applied just before the loop | |
Object n = new Object(); | |
for(int i=0; i < 2; i++) { | |
int[] arr = new int[]{1, 1}; // (2) no abstraction applied | |
if(arr[1] == 2) { | |
n = null; // Infer judges here non-reacheable if (2) is present | |
} | |
} | |
return n; | |
} | |
public static void main(String[] args) { | |
f().toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment