Open
Description
Example 1:
extern int arr[];
int main(){
int *p = arr;
int a = *p;
return 0;
}
int arr[] = {1,2};
Example 2:
extern int arr[];
int arr[] = {1,2};
int main(){
int *p = arr;
int a = *p;
return 0;
}
In Example 1, I run cbmc <filename.c> --pointer-check
and cbmc gave FAILURE result with the message dereference failure: pointer outside object bounds in *p: FAILURE
.
Then I moved this statement int arr[] = {1,2};
forward to get Example 2. And the pointer-check
result became SUCCESSFUL.
In the two examples, p
both pointed to the array arr[]
. Why did pointer-check
give different results? Is it releated to the extern
keyword?
Please help me to explain this situation. Thanks.
CBMC version: 5.88.0
Operating system: Ubuntu 22.04, MacOS