|
|
This section lists alphabetically the warning messages
issued exclusively
by lint or subject exclusively to its options.
The code examples illustrate conditions in which the messages are elicited.
Note that some of the examples would elicit
messages in addition to the one stated.
For the remaining lint messages, consult
``C compiler diagnostics''.
argument unused in function/
ARGSUSEDn
/ suppresses
the message for all but the first n arguments;
invoking lint with -v suppresses
it for every argument.
1 int fun(int x, int y)
2 {
3 return x;
4 }
5 /
ARGSUSED1
/
6 int fun2(int x, int y)
7 {
8 return x;
9 }
============
argument unused in function
(1) y in fun
array subscript cannot be > value: value1 int fun()
2 {
3 int a[10];
4 int
p = a;
5 while (p != &a[10]) /
using address is ok
/
6 p++;
7 return a[5 + 6];
8 }
============
(7) warning: array subscript cannot be > 9: 11
array subscript cannot be negative: value1 int f()
2 {
3 int a[10];
4 return a[5
2 / 10 - 2];
5 }
============
(4) warning: array subscript cannot be negative: -1
assignment causes implicit narrowing conversion1 void fun()
2 {
3 short s;
4 long l = 0;
5 s = l;
6 }
============
assignment causes implicit narrowing conversion
(5)
assignment of negative constant to unsigned type1 void fun()
2 {
3 unsigned i;
4 i = -1;
5 i = -1U;
6 i = (unsigned) (-4 + 3);
7 }
============
(4) warning: assignment of negative constant to unsigned type
assignment operator = found where == was expected1 void fun()
2 {
3 char
p,
q;
4 int a = 0, b = 0, c = 0, d = 0, i;
5 i = (a = b) && (c == d);
6 i = (c == d) && (a = b);
7 if (a = b)
8 i = 1;
9 while (
p++ =
q++);
10 while (a = b);
11 while ((a = getchar()) == b);
12 if (a = foo()) return;
13 }
============
(5) warning: assignment operator "=" found where "=="
was expected
(7) warning: assignment operator "=" found where "=="
was expected
(10) warning: assignment operator "=" found where "=="
was expected
bitwise operation on signed value nonportable1 fun()
2 {
3 int i;
4 signed int j;
5 unsigned int k;
6 i = i & 055;
7 j = j | 022;
8 k = k >> 4;
9 }
============
warning: bitwise operation on signed value nonportable
(6) (7)
constant in conditional context/
CONSTCOND
/ suppresses
the message.
1 void fun()
2 {
3 if (! 1) return;
4 while (1) foo();
5 for (;1;);
6 for (;;);
7 /
CONSTCOND
/
8 while (1);
9 }
============
(3) warning: constant in conditional context
(4) warning: constant in conditional context
(5) warning: constant in conditional context
constant operand to op: !/
CONSTCOND
/
suppresses the message
for that statement; invoking lint with -h
suppresses it for every statement.
1 void fun()
2 {
3 if (! 0) return;
4 /
CONSTCOND
/
5 if (! 0) return;
6 }
============
(3) warning: constant operand to op: "!"
constant truncated by assignment1 unsigned char f()
2 {
3 unsigned char i;
4 i = 255;
5 i = 256;
6 return 256;
7 }
============
(5) warning: constant truncated by assignment
(6) warning: constant truncated by assignment
conversion of pointer loses bits1 void fun()
2 {
3 char c;
4 int
i;
5 c = i;
6 }
============
(5) warning: conversion of pointer loses bits
conversion to larger integral type may sign-extend incorrectly1 void fun()
2 {
3 char c = 0;
4 short s = 0;
5 long l;
6 l = c;
7 l = s;
8 }
============
conversion to larger integral type may sign-extend incorrectly
(6)
declaration unused in block1 int fun()
2 {
3 int foo();
4 int bar();
5 return foo();
6 }
============
declaration unused in block
(4) bar
declared global, could be staticfile: f1.c
1 int i;
2 int foo() {return i;}
3 int fun() {return i;}
4 static int stfun() {return fun();}
file: f2.c
1 main()
2 {
3 int a;
4 a = foo();
5 }
============
declared global, could be static
fun f1.c(3)
i f1.c(1)
equality operator == found where ?=? was expected1 void fun(a, b)
2 int a, b;
3 {
4 a == b;
5 for (a == b; a < 10; a++);
6 }
============
(4) warning: equality operator "==" found where "="
was expected
(5) warning: equality operator "==" found where "="
was expected
evaluation order undefined: name1 int a[10];
2 main()
3 {
4 int i = 1;
5 a[i++] = i;
6 }
============
(5) warning: evaluation order undefined: i
fallthrough on case statement/
FALLTHRU
/,
or /
NOTREACHED
/ when the
case cannot be reached from the preceding case (see below), suppresses the message for that statement;
invoking lint with -h suppresses it for every statement.
1 void fun(i)
2 {
3 switch (i) {
4 case 10:
5 i = 0;
6 case 12:
7 return;
8 case 14:
9 break;
10 case 15:
11 case 16:
12 break;
13 case 18:
14 i = 0;
15 /
FALLTHRU
/
16 case 20:
17 error("bad number");
18 /
NOTREACHED
/
19 case 22:
20 return;
21 }
22 }
============
(6) warning: fallthrough on case statement
function argument ( number ) declared inconsistentlyfile: i3a.c 1 int fun1(int); 2 int fun2(int); 3 int fun3(int);file: i3b.c 1 int fun1(int
i); 2 int fun2(int
i) {} 3 void foo() 4 { 5 int
i; 6 fun3(i); 7 } ============ function argument ( number ) declared inconsistently fun2 (arg 1) i3b.c(2) int
:: i3a.c(2) int fun1 (arg 1) i3a.c(1) int :: i3b.c(1) int
function argument ( number ) used inconsistently fun3 (arg 1) i3a.c(3) int :: i3b.c(6) int
![]()
function argument ( number ) used inconsistentlyfile: f1.c
1 int fun(int x, int y)
2 {
3 return x + y;
4 }
file: f2.c
1 int main()
2 {
3 int
x;
4 extern int fun();
5 return fun(1, x);
6 }
============
function argument ( number ) used inconsistently
fun( arg 2 ) f1.c(2) int :: f2.c(5) int
function argument type inconsistent with format/
PRINTFLIKEn
/ and
/
SCANFLIKEn
/ in
the list of directives in
``Using lint''.)
1 #include <stdio.h>
2 main()
3 {
4 int i;
5 printf("%s", i);
6 }
============
function argument type inconsistent with format
printf(arg 2) int :: (format) char
test.c(5)
function called with variable number of arguments/
VARARGSn
/
suppresses the message for calls with n or more arguments;
defining and declaring a function with the ANSI C notation
``. . .'' suppresses it for every argument.
function declared with variable number of arguments''
for more information.
file: f1.c
1 int fun(int x, int y, int z)
2 {
3 return x + y + z;
4 }
5 int fun2(int x, . . .)
6 {
7 return x;
8 }
10 /
VARARGS1
/
11 int fun3(int x, int y, int z)
12 {
13 return x;
14 }
file: f2.c
1 int main()
2 {
3 extern int fun(), fun3(), fun2(int x, . . .);
4 return fun(1, 2);
5 return fun2(1, 2, 3, 4);
6 return fun3(1, 2, 3, 4, 5);
7 }
============
function called with variable number of arguments
fun f1.c(2) :: f2.c(4)
function declared with variable number of argumentsfile: i3a.c 1 int fun1(int); 2 int fun2(int); 3 int fun3(int);file: i3b.c 1 int fun1(int, int); 2 int fun2(int a, int b) {} 3 void foo() 4 { 5 int i, j, k; 6 i = fun3(j, k); 7 } ============ function declared with variable number of arguments fun2 i3a.c(2) :: i3b.c(2) fun1 i3a.c(1) :: i3b.c(1) function called with variable number of arguments fun3 i3a.c(3) :: i3b.c(6)
function falls off bottom without returning value/
NOTREACHED
/ suppresses the message.
1 fun()
2 {}
3 void fun2()
4 {}
5 foo()
6 {
7 exit(1);
8 /
NOTREACHED
/
9 }
============
function falls off bottom without returning value
(2) fun
function must return int: main()1 void main()
2 {}
============
(2) warning: function must return int: main()
function returns pointer to [automatic/parameter]1 intfun(int x) 2 { 3 int a[10]; 4 int b; 5 if (x == 1) 6 return a; 7 else if (x == 2) 8 return &b ; 9 else return &x ; 10 } ============ (6) warning: function returns pointer to automatic (8) warning: function returns pointer to automatic (9) warning: function returns pointer to parameter
function returns value that is always ignoredfile: f1.c
1 int fun()
2 {
3 return 1;
4 }
file: f2.c
1 extern int fun();
2 int main()
3 {
4 fun();
5 return 1;
6 }
============
function returns value that is always ignored
fun
function returns value that is sometimes ignoredfile: f1.c
1 int fun()
2 {
3 return 1;
4 }
file: f2.c
1 extern int fun();
2 int main()
3 {
4 if(1) {
5 return fun();
6 }
else {
7 fun();
8 return 1;
9 }
10 }
============
function returns value that is sometimes ignored
fun
function value is used, but none returnedfile: f1.c
1 extern int fun();
2 main()
3 {
4 return fun();
5 }
file: f2.c
1 int fun()
2 {}
============
function value is used, but none returned
fun
logical expression always false: op &&/
CONSTCOND
/ suppresses the message.
1 void fun(a)
2 int a;
3 {
4 a = (a == 1) && (a == 2);
5 a = (a == 1) && (a == 1);
6 a = (1 == a) && (a == 2);
7 a = (a == 1) && 0;
8 /
CONSTCOND
/
9 a = (0 && (a == 1));
10 }
============
(4) warning: logical expression always false: op "&&"
(6) warning: logical expression always false: op "&&"
(7) warning: logical expression always false: op "&&"
logical expression always true: op ||/
CONSTCOND
/ suppresses the message.
1 void fun(a)
2 int a;
3 {
4 a = (a != 1) || (a != 2);
5 a = (a != 1) || (a != 1);
6 a = (1 != a) || (a != 2);
7 a = (a == 10) || 1;
8 /
CONSTCOND
/
9 a = (1 || (a == 10));
10 }
============
(4) warning: logical expression always true: op "||"
(6) warning: logical expression always true: op "||"
(7) warning: logical expression always true: op "||"
malformed format string/
PRINTFLIKEn
/ and
/
SCANFLIKEn
/
in the list of directives in
``Using lint''.)
1 #include <stdio.h>
2 main()
3 {
4 printf("%y");
5 }
============
malformed format string
printf test.c(4)
may be indistinguishable due to truncation or casefile: f1.c 1 int foobar1; 2 int FooBar12;file: f2.c 1 int foobar2; 2 int FOOBAR12; ============
under -p may be indistinguishable due to truncation or case FooBar12 f1.c(2) :: FOOBAR12 f2.c(2)
under -Xc may be indistinguishable due to truncation or case foobar1 f1.c(1) :: FooBar12 f1.c(2) foobar1 f1.c(1) :: foobar2 f2.c(1) foobar1 f1.c(1) :: FOOBAR12 f2.c(2)
name declared but never used or definedfile f.c
1 extern int fun();
2 static int foo();
============
name declared but never used or defined
fun f.c(1)
name defined but never usedfile f.c
1 int i, j, k = 1;
2 main()
3 {
4 j = k;
5 }
============
name defined but never used
i f.c(1)
name multiply definedfile f1.c 1 char i = 'a';file f2.c 1 long i = 1; ============ name multiply defined i f1.c(1) :: f2.c(1)
name used but not definedfile f.c
1 extern int fun();
2 int main()
3 {
4 return fun();
5 }
============
name used but not defined
fun f.c(4)
nonportable bit-field type1 struct u {
2 unsigned v:1;
3 int w:1;
4 char x:8;
5 long y:8;
6 short z:8;
7 };
============
(3) warning: nonportable bit-field type
(4) warning: nonportable bit-field type
(5) warning: nonportable bit-field type
(6) warning: nonportable bit-field type
nonportable character constant1 int c = 'abc'; ============ (1) warning: nonportable character constant
only 0 or 2 parameters allowed: main()1 main(int argc, charargv, char
envp) 2 {} ============ (2) warning: only 0 or 2 parameters allowed: main()
pointer cast may result in improper alignment1 void fun()
2 {
3 short
s;
4 int
i;
5 i = (int
) s;
6 }
============
pointer cast may result in improper alignment
(5)
pointer casts may be troublesome
.
1 void fun()
2 {
3 int
i;
4 char
c;
5 void
v;
6 i = (int
) c;
7 i = (int
) v;
8 }
============
warning: pointer casts may be troublesome
(6)
precedence confusion possible; parenthesize1 void fun()
2 {
3 int x = 0, m = 0, MASK = 0, i;
4 i = (x + m == 0);
5 i = (x & MASK == 0); /
eval'd (x & (MASK == 0))
/
6 i = (MASK == 1 & x); /
eval'd ((MASK == 1) & x)
/
7 }
============
(5) warning: precedence confusion possible; parenthesize
(6) warning: precedence confusion possible; parenthesize
precision lost in bit-field assignment1 void fun()
2 {
3 struct {
4 signed x:3; /
max value allowed is 3
/
5 unsigned y:3; /
max value allowed is 7
/
6 int z:3; /
max value allowed is 7
/
7 } s;
8 s.x = 3;
9 s.x = 4;
10 s.y = 7;
11 s.y = 8;
12 s.z = 7;
13 s.z = 8;
14 }
============
(9) warning: precision lost in bit-field assignment: 4
(11) warning: precision lost in bit-field assignment: 0x8
(13) warning: precision lost in bit-field assignment: 8
set but not used in function1 void fun(y)
2 int y;
3 {
4 int x;
5 x = 1;
6 y = 1;
7 }
============
set but not used in function
(4) x in fun
(1) y in fun
statement has no consequent: else/
EMPTY
/ between the else and semicolon
suppresses the message for that statement;
invoking lint with -h suppresses it for every statement.
1 void f(a)
2 int a;
3 {
4 if (a)
5 return;
6 else;
7 }
============
(6) warning: statement has no consequent: else
statement has no consequent: if/
EMPTY
/ between the controlling expression of the
if and semicolon suppresses the message for that statement;
invoking lint with -h suppresses it for every statement.
1 void f(a)
2 int a;
3 {
4 if (a);
5 if (a == 10)
6 /
EMPTY
/;
7 else return;
8 }
============
(4) warning: statement has no consequent: if
statement has null effect1 void fun()
2 {
3 int a, b, c, x;
4 a;
5 a == 5;
6 ;
7 while (x++ != 10);
8 (a == b) && (c = a);
9 (a = b) && (c == a);
10 (a, b);
11 }
============
statement has null effect
(4) (5) (9) (10)
statement not reached/
NOTREACHED
/
suppresses the message for that statement;
invoking lint with -b suppresses
it for every unreached break and empty statement.
Note that this message is also issued by the compiler but cannot be suppressed.
1 void fun(a)
2 {
3 switch (a) {
4 case 1:
5 return;
6 break;
7 case 2:
8 return;
9 /
NOTREACHED
/
10 break;
11 }
12 }
============
statement not reached
(6)
static unused1 static int x;
2 static int main() {}
3 static int foo();
4 static int y = 1;
============
static unused
(4) y (3) foo (2) main (1) x
suspicious comparison of char with value: op op1 void fun(c, d)
2 char c;
3 signed char d;
4 {
5 int i;
6 i = (c == -5);
7 i = (c < 0);
8 i = (d < 0);
9 }
============
(6) warning: suspicious comparison of char with negative
constant: op "=="
(7) warning: suspicious comparison of char with 0: op "<"
suspicious comparison of unsigned with value: op "op"1 void fun(x)
2 unsigned x;
3 {
4 int i;
5 i = (x > -2);
6 i = (x < 0);
7 i = (x <= 0);
8 i = (x >= 0);
9 i = (x > 0);
10 i = (-2 < x);
11 i = (x == -1);
12 i = (x == -1U);
13 }
============
(5) warning: suspicious comparison of unsigned with negative
constant: op ">"
(6) warning: suspicious comparison of unsigned with 0: op "<"
(7) warning: suspicious comparison of unsigned with 0: op "<="
(8) warning: suspicious comparison of unsigned with 0: op ">="
(9) warning: suspicious comparison of unsigned with 0: op ">"
(10) warning: suspicious comparison of unsigned with negative
constant: op "<"
(11) warning: suspicious comparison of unsigned with negative
constant: op "=="
too few arguments for format/
PRINTFLIKEn
/ and
/
SCANFLIKEn
/
in the list of directives in
``Using lint''.)
1 #include <stdio.h>
2 main()
3 {
4 int i;
5 printf("%d%d", i);
6 }
============
too few arguments for format
printf test.c(5)
too many arguments for format/
PRINTFLIKEn
/ and
/
SCANFLIKEn
/
in the list of directives in
``Using lint''.)
1 #include <stdio.h>
2 main()
3 {
4 int i, j;
5 printf("%d", i, j);
6 }
============
too many arguments for format
printf test.c(5)
value type declared inconsistentlyfile f1.c
1 void fun() {}
2 void foo();
3 extern int a;
file f2.c
1 extern int fun();
2 extern int foo();
3 extern char a;
============
value type declared inconsistently
fun f1.c(1) void() :: f2.c(1) int()
foo f1.c(2) void() :: f2.c(2) int()
a f1.c(3) int :: f2.c(3) char
value type used inconsistentlyfile f1.c 1 intfun(p) 2 int
p; 3 { 4 return p; 5 }
file f2.c 1 main() 2 { 3 int i,
p; 4 i = fun(p); 5 } ============ value type used inconsistently fun f1.c(3) int
() :: f2.c(4) int()
variable may be used before set: name1 void fun()
2 {
3 int i, j, k;
4 static int x;
5 k = j;
6 i = i + 1;
7 x = x + 1;
8 }
============
(5) warning: variable may be used before set: j
(6) warning: variable may be used before set: i
variable unused in function1 void fun()
2 {
3 int x, y;
4 static z;
5 }
============
variable unused in function
(4) z in fun
(3) y in fun
(3) x in fun