Ubuntu下面的C语言代码查抄工具Splint[Linux安全]
本文“Ubuntu下面的C语言代码查抄工具Splint[Linux安全]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
看一下下面的代码(当然包含错误,以查验splint的功效):
#include
int main(int argc,char* argv[]){
int a=100; /*没有利用的变量*/
int b[8];
printf("Hello c\n");
b[9]=100; /*明显数组越界 */
/* 用到了两个为声明的变量c和d/
c=100;
d=10;
return 0;
}
目前可以用splint来查抄一下,为了查验能否可以检测到数组越界,利用+bounds选项.
splint hi.c +bounds
输出后果:
hi.c: (in function main)
hi.c:9:2: Unrecognized identifier: c
Identifier used in code has not been declared. (Use -unrecog to inhibit
warning)
hi.c:10:2: Unrecognized identifier: d
hi.c:4:6: Variable a declared but not used
A variable is declared but never used. Use /*@unused@*/ in front of
declaration to suppress message. (Use -varuse to inhibit warning)
hi.c:7:2: Likely out-of-bounds store:
b[9]
Unable to resolve constraint:
requires 7 >= 9
needed to satisfy precondition:
requires maxSet(b @ hi.c:7:2) >= 9
A memory write may write to an address beyond the allocated buffer. (Use
-likely-boundswrite to inhibit warning)
hi.c:3: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)
hi.c:3:25: Parameter argv not used
Finished checking --- 6 code warnings
以上是“Ubuntu下面的C语言代码查抄工具Splint[Linux安全]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |