Source code analysis detects inconsistent object declarations in different program units, for example:
Different external objects with the same name.
Inconsistent declarations of a COMMON block (Fortran-specific).
Mismatched number of arguments.
Mismatched type, rank, shape, or/and size of an argument.
Inconsistent declaration of a procedure.
The following examples illustrate interprocedural analysis.
Example 1: Wrong number of arguments
File f1.c contains this function declaration:
1 void Do_hello() {
2 printf("helo everybody!\n");
}
File f2.c contains a call to the routine:
1 extern void Do_hello(int);
2
3 void foo() {
4 Do_hello ( 1 ) ;
5 }
The source checker issues the following message:
f2.c(4): error #12020: number of actual arguments (1) in call of "Do_hello" doesn't match the number of formal arguments (0); "Do_hello" is defined at (file:f1.c line:1)
The other goal of interprocedural analysis is to propagate information about program objects across the program through procedure calls. The following information is propagated :
Example 2: Out of Boundaries
This example demonstrates the propagation of pointer A to Arr and the constant value 5 to x:
1 void foo( int* Arr, int x) {
2 for(; 0<=x; x--) {
3 Arr[x] = x;
4 }
5 }
6
7 void bar() {
8 int A[5];
9 foo(A,5);
10 }
The source checker issues the following message:
f1.c(3): error #12255: Buffer overflow: index is possibly outside the bounds for array "A" which is passed as actual argument 1 to "foo" at (file:f2.c line:9); array "A" of size (0:4) can be indexed by value 5