Skip to content

Commit

Permalink
Add test for nullpointer.dereference.refine
Browse files Browse the repository at this point in the history
  • Loading branch information
karoliineh committed Sep 13, 2023
1 parent ceaf644 commit d54c31d
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// PARAM: --enable sem.null-pointer.dereference-refine
#include <stdio.h>

struct person {
int age;
int height;
int* ptr;
};

int main(){
int r1, r2, p;
int *a = NULL;
int *b;

switch(r1) {
case 1:
*a = 10; // WARN
__goblint_check(0); // NOWARN (unreachable)
break;
case 2:
*a = 10; // WARN
__goblint_check(0); // NOWARN (unreachable)
break;
case 3:
*b = 10; // WARN
p = *b; // NOWARN
case 4:
if (r2) {
struct person new_person = {1,1, NULL};
p = *(new_person.ptr); // WARN
} else {
int test = 3;
struct person non_null = {1,1, &test};
p = *(non_null.ptr);
}
__goblint_check(p != NULL); // reachable
break;
// TODO: case 5: nullpointer in if condition
// TODO: case 6: nullpointer as a function argument
default:
// code block
break;
}
return 1;
}

0 comments on commit d54c31d

Please sign in to comment.