c - 使用 Sparse 检查 C 代码

标签 c linux sparse-matrix static-analysis

有没有人有过 Sparse 的经验? ?我似乎无法找到任何文档,因此我不清楚它产生的警告和错误。我尝试查看邮件列表和手册页,但实际上两者都没有太多内容。

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

错误和警告有没有解释的地方?

最佳答案

据说,Sparse 并不是为了成为 lint。稀疏旨在生成任意代码的解析树,以便对其进行进一步分析。

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

我会避免单独定义 __GNUC__,因为如果没有定义 GNU_SOURCE 打开的所有其他开关,它激活的一些东西可能会以未定义的方式运行。

我的意思不是帮助您逐个消除错误,而是重申稀疏主要用作库,而不是作为独立的静态分析工具。

来 self 的 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 - 使用 Sparse 检查 C 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1818473/

相关文章:

c - 使用默认(私有(private))子句时出现 OpenMP 错误

c++ - 标准 C++ 中是否有一种可移植的方法来检索主机名?

r - R 中的 xgboost 预测在稀疏矩阵和稠密矩阵上是不同的

cuda - CUSPARSE_STATUS_INTERNAL_ERROR 与 cuSparse cusparseSnnz 函数

c - 如何从文本文件读取数据并将其存储在我的 C 程序中以便在函数中使用?

c - AES (aes-ige-128, aes-ige-192, aes-ige-256) 加密/解密与 openssl C

c++ - 无法在守护进程中打开 ttyUSB 端口

c# - 在 C# 中,如何使用 Excel Interop 来加速写入多个单元格值

python - 自动化 vi/nano 编辑器进行 git commit --amend

c - 现代终端通常会正确呈现所有 utf-8 字符吗?