I've been working on some older C code. I found out that there are quite some POSIX calls that are now outdated and marked deprecated in the manual pages.
我一直在研究一些旧的C代码。我发现有很多POSIX调用现已过时,并在手册页中标记为已弃用。
What's the best way to check if there are still deprecated POSIX calls in your code? I'm thinking of either:
检查代码中是否仍有弃用的POSIX调用的最佳方法是什么?我想的是:
- special gcc warning options.
- some kind of lint tool detecting these calls.
特殊的gcc警告选项。
检测这些调用的某种lint工具。
2 个解决方案
#1
Lint can find deprecated things (-deprecated flag).
Lint可以找到弃用的东西(-deprecated flag)。
Coverity finds this kind of issue routinely with c and c++ codebases.
Coverity通常使用c和c ++代码库来发现这种问题。
Additionally, and perhaps more importantly, static analysis tools find a very much wider range of issues and bugs.
此外,也许更重要的是,静态分析工具可以找到更广泛的问题和错误。
You can never have too much static code analysis. There is benefit from using several tools.
您永远不会有太多的静态代码分析。使用多种工具可以获益。
#2
My first attempt would be a simple tool using grep
(even though it may throw up false positives).
我的第一次尝试是使用grep的简单工具(即使它可能会引发误报)。
>> cd src_dir
>> cat deprecated_calls
printf
strcpy
>> for i in $(cat deprecated_calls) ; do
+> grep -R $i .
+> done
binmath.c:printf (" 0 sum:[%s]\n",sum);
binmath.c:printf (" 100 sum:[%s]\n",sum);
binmath.c:printf (" 200 sum:[%s]\n",sum);
binmath.c:printf (" 300 sum:[%s]\n",sum);
qq.c:printf("%d %d %d\n",i,j,k);
xx.c: fprintf (stderr, "Cannot open 'words.txt', error = %d\n", errno);
binmath.c:strcpy (buff, "0");
oldstuff/qq.c:printf("%d %d %d\n",i,j,k);
I doubt you need a full-blown parser-type tool for this.
我怀疑你需要一个完整的解析器类型的工具。
#1
Lint can find deprecated things (-deprecated flag).
Lint可以找到弃用的东西(-deprecated flag)。
Coverity finds this kind of issue routinely with c and c++ codebases.
Coverity通常使用c和c ++代码库来发现这种问题。
Additionally, and perhaps more importantly, static analysis tools find a very much wider range of issues and bugs.
此外,也许更重要的是,静态分析工具可以找到更广泛的问题和错误。
You can never have too much static code analysis. There is benefit from using several tools.
您永远不会有太多的静态代码分析。使用多种工具可以获益。
#2
My first attempt would be a simple tool using grep
(even though it may throw up false positives).
我的第一次尝试是使用grep的简单工具(即使它可能会引发误报)。
>> cd src_dir
>> cat deprecated_calls
printf
strcpy
>> for i in $(cat deprecated_calls) ; do
+> grep -R $i .
+> done
binmath.c:printf (" 0 sum:[%s]\n",sum);
binmath.c:printf (" 100 sum:[%s]\n",sum);
binmath.c:printf (" 200 sum:[%s]\n",sum);
binmath.c:printf (" 300 sum:[%s]\n",sum);
qq.c:printf("%d %d %d\n",i,j,k);
xx.c: fprintf (stderr, "Cannot open 'words.txt', error = %d\n", errno);
binmath.c:strcpy (buff, "0");
oldstuff/qq.c:printf("%d %d %d\n",i,j,k);
I doubt you need a full-blown parser-type tool for this.
我怀疑你需要一个完整的解析器类型的工具。