The lint program can, with certain options, show precise source file lines with pointers to the line position where the error occurred. The option enabling this feature is -errfmt=f. Under this option, lint provides the following information:
Source line(s) and position(s)
Macro unfolding
Error-prone stack(s)
For example, the following program, Test1.c, contains an error.
1 #include <string.h>
2 static void cpv(char *s, char* v, unsigned n)
3 { int i;
4 for (i=0; i<=n; i++){
5 *v++ = *s++;}
6 }
7 void main(int argc, char* argv[])
8 {
9 if (argc != 0){
10 cpv(argv[0], argc, strlen(argv[0]));}
11}
|
Using lint on Test1.c with the option:
% lint -errfmt=src -Nlevel=2 Test1.c |
produces the following output:
|static void cpv(char *s, char* v, unsigned n)
| ^ line 2, Test1.c
|
| cpv(argv[0], argc, strlen(argv[0]));
| ^ line 10, Test1.c
warning: improper pointer/integer combination: arg #2
|
|static void cpv(char *s, char* v, unsigned n)
| ^ line 2, Test1.c
|
|cpv(argv[0], argc, strlen(argv[0]));
| ^ line 10, Test1.c
|
| *v++ = *s++;
| ^ line 5, Test1.c
warning:use of a pointer produced in a questionable way
v defined at Test1.c(2) ::Test1.c(5)
call stack:
main() , Test1.c(10)
cpv() , Test1.c(5)
|
The first warning indicates two source lines that are contradictory. The second warning shows the call stack, with the control flow leading to the error.
Another program, Test2.c, contains a different error:
1 #define AA(b) AR[b+l]
2 #define B(c,d) c+AA(d)
3
4 int x=0;
5
6 int AR[10]={1,2,3,4,5,6,77,88,99,0};
7
8 main()
9 {
10 int y=-5, z=5;
11 return B(y,z);
12 }
|
Using lint on Test2.c with the option:
% lint -errfmt=macro Test2.c |
produces the following output, showing the steps of macro substitution: