得分:10
用splint检测后结果如下,供参考
Splint 3.1.2 --- 03 May 2009
test.c: (in function main)
test.c:12:18: Format argument 1 to scanf (%d) expects int * gets unsigned int
*: &num
To ignore signs in type comparisons use +ignoresigns
test.c:12:13: Corresponding format code
test.c:12:5: Return value (type int) ignored: scanf("%d\n", &num)
Result returned by function call is not used. If this is intended, can cast
result to (void) to eliminate message. (Use -retvalint to inhibit warning)
test.c:14:13: Operands of < have incompatible types (int, unsigned int):
i < num
test.c:17:9: Use of gets leads to a buffer overflow vulnerability. Use fgets
instead: gets
Use of function that may lead to buffer overflow. (Use -bufferoverflowhigh to
inhibit warning)
test.c:17:9: Return value (type char *) ignored: gets(*(ch + i))
Result returned by function call is not used. If this is intended, can cast
result to (void) to eliminate message. (Use -retvalother to inhibit warning)
test.c:20:20: Index of null pointer ch: ch
A possibly null pointer is dereferenced. Value is either the result of a
function which may return null (in which case, code should check it is not
null), or a global, parameter or structure field declared with the null
qualifier. (Use -nullderef to inhibit warning)
test.c:9:15: Storage ch becomes null
test.c:20:9: Assignment of arbitrary unsigned integral type to int:
len = strlen(ch[i]) - 1
To allow arbitrary integral types to match any integral type, use
+matchanyintegral.
test.c:23:13: Assignment of char to int: n = ch[i][j]
To make char and int types equivalent, use +charint.
test.c:57:17: Operands of < have incompatible types (int, unsigned int):
i < num
test.c:60:21: Operands of < have incompatible types (int, unsigned int):
j < num
test.c:71:17: No argument corresponding to printf format code 2 (%d):
"%s %d\n"
Types are incompatible. (Use -type to inhibit warning)
test.c:71:30: Corresponding format code
test.c:76:2: Path with no return in function declared to return int
There is a path through a function declared to return a value on which there
is no return statement. This means the execution may fall through without
returning a meaningful result to the caller. (Use -noret to inhibit warning)
test.c:5:14: Parameter argc not used
A function parameter is not used in the body of the function. If the argument
is needed for type compatibility or future plans, use /*@unused@*/ in the
argument declaration. (Use -paramuse to inhibit warning)
test.c:5:25: Parameter argv not used
Finished checking --- 14 code warnings
经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。