ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

使用Sparse检查C代码

2019-06-07 07:37:48  阅读:283  来源: 互联网

标签:c-3 linux static-analysis sparse-matrix


有没有人有Sparse的经验?我似乎无法找到任何文档,所以警告和它产生的错误对我来说都不清楚.我尝试检查邮件列表和手册页,但实际上并没有多少.

例如,我在我的一个文件中使用INT_MAX.即使我#include limits.h,这也会产生错误(未定义的标识符).

是否有任何地方可以解释错误和警告?

解决方法:

根据说,稀疏并不是一个棉绒.稀疏旨在生成任意代码的解析树,以便可以进一步分析.

在您的示例中,您要么定义GNU_SOURCE(我相信它会打开__GNUC__),它会在limits.h中公开您需要的位.

我会避免单独定义__GNUC__,因为它激活的几个东西可能会以未定义的方式运行,而没有GNU_SOURCE打开的所有其他开关被定义.

我的观点不是帮助你按错误压缩错误,而是重申稀疏主要用作库,而不是作为独立的静态分析工具.

从我的README副本(不确定我是否有当前版本):

This means that a user of the library will literally just need to do

  struct string_list *filelist = NULL;
  char *file;

  action(sparse_initialize(argc, argv, filelist));

  FOR_EACH_PTR_NOTAG(filelist, file) {
    action(sparse(file));
  } END_FOR_EACH_PTR_NOTAG(file);

and he is now done - having a full C parse of the file he opened.  The
library doesn't need any more setup, and once done does not impose any
more requirements.  The user is free to do whatever he wants with the
parse tree that got built up, and needs not worry about the library ever
again.  There is no extra state, there are no parser callbacks, there is
only the parse tree that is described by the header files. The action
function takes a pointer to a symbol_list and does whatever it likes with it.

The library also contains (as an example user) a few clients that do the
preprocessing, parsing and type evaluation and just print out the
results.  These clients were done to verify and debug the library, and
also as trivial examples of what you can do with the parse tree once it
is formed, so that users can see how the tree is organized.

包含的客户端比任何东西都更像是“功能测试套件和示例”.它是一个非常有用的工具,但如果你想使用它,你可能会考虑另一个使用角度.我喜欢它,因为它不使用* lex / bison,这使得它非常容易破解.

标签:c-3,linux,static-analysis,sparse-matrix
来源: https://codeday.me/bug/20190607/1192038.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有