lint プログラムは、特定のオプションが指定されている場合、エラーが発生した位置にポインタが表示されている状態で正確なソースファイルの行を表示できます。この機能を有効化するオプションは -errfmt=f で、lint から次の情報が提供されます。
ソースの行と位置
マクロの展開
エラーを起こしやすいスタック
たとえば、次に示すプログラム Test1.c にはエラーがあります。
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}
Test1.c に対して lint を —errfmt=src オプション付きで使用すると、次の出力が生成されます。
% lint -errfmt=src -Nlevel=2 Test1.c |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)
1 つめの警告は、2 つのコード行の間で矛盾があることを示しています。2 つめの警告には、コールスタックとエラーになるまでの制御フローが表示されます。
次に示すプログラム Test2.c には、前述のものとは異なる種類のエラーがあります。
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 }
Test2.c に対して lint を -errfmt=macro オプション付きで使用すると、次の出力が生成され、マクロ置換の手順が表示されます。
% lint -errfmt=macro Test2.c | return B(y,z); | ^ line 11, Test2.c | |#define B(c,d) c+AA(d) | ^ line 2, Test2.c | |#define AA(b) AR[b+l] | ^ line 1, Test2.c error: undefined symbol: l | | return B(y,z); | ^ line 11, Test2.c | |#define B(c,d) c+AA(d) | ^ line 2, Test2.c | |#define AA(b) AR[b+l] | ^ line 1, Test2.c variable may be used before set: l lint: errors in Test2.c; no output created lint: pass2 not run - errors in Test2.c