软件测试实验学习笔记系列2 -- lint,splint的使用

发表于:2013-8-05 11:05

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:xiajian2010    来源:51Testing软件测试网博客

分享:

  splint命令:splint typeerr.c

  splint执行的结果:

  Splint 3.1.2--- 03 May 2009
  typeerr.c:(in function foo)
  typeerr.c:3:5:Test expression for if is assignment expression: i = 3
  Thecondition test is an assignment expression. Probably, you mean to use==
  instead of=. If an assignment is intended, add an extra parentheses nesting
  (e.g., if((a = b)) ...) to suppress this message. (Use -predassign to
  inhibitwarning)

  #错误类型:if语句中的条件表达式是一个赋值语句。

  typeerr.c:3:5:Test expression for if not boolean, type int: i = 3
  Testexpression type is not boolean or int. (Use -predboolint to inhibit
  warning)

  #错误类型:if语句中的条件表达式返回值不是bool类型而是int类型

  typeerr.c:3:17:Return value type bool does not match declared type int: b1
  Types areincompatible. (Use -type to inhibit warning)

  #错误类型:!的操作数不是bool类型而是int类型的i

  typeerr.c:4:6:Operand of ! is non-boolean (int): !i
  Theoperand of a boolean operator is not a boolean. Use +ptrnegate toallow !
  to be usedon pointers. (Use -boolops to inhibit warning)

  #错误类型:||操作符的右操作数不是bool类型而是整型

  typeerr.c:4:11:Right operand of || is non-boolean (char *): !i || s

  ##错误类型:不应该使用==对两个bool类型进行比较,而应该使用&&

  typeerr.c:6:5:Use of == with boolean variables (risks inconsistency because of
  multipletrue values): b1 == b2
  Two boolvalues are compared directly using a C primitive. This may produce
  unexpectedresults since all non-zero values are considered true, so
  differenttrue values may not be equal. The file bool.h (included in
  splint/lib)provides bool_equal for safe bool comparisons. (Use -boolcompare
  to inhibitwarning)
  Finishedchecking --- 6 code warnings

  实例2.malloc1.c

/*Program: malloc1.c -- check varible type */
#include<stdlib.h>
#include<stdio.h>
int main(){
 char * some_mem;
 int size1 = 1048567;
 //size_t size1 = 1048567;
 some_mem = (char*) malloc(size1);
 printf("Malloced 1M Memory!\n");
 free(some_mem);
 exit(EXIT_SUCCESS);
}

  splint命令:splint malloc1.c

  使用是splint检查malloc1.c

  Splint 3.1.2--- 03 May 2009
  malloc1.c:(in function main)
  malloc1.c:8:28:Function malloc expects arg 1 to be size_t gets int: size1
  To allowarbitrary integral types to match any integral type, use
  +matchanyintegral.

  将size1的定义修改为:

  size_t size1= 1048567;

  再次使用splint将行检查:splintmalloc1.c

  Splint 3.1.2--- 03 May 2009
  Finishedchecking --- no warnings

43/4<1234>
精选软件测试好文,快来阅读吧~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号