Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to check if C code has deprecated POSIX calls?

Tags:

c

linux

unix

gcc

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.

What's the best way to check if there are still deprecated POSIX calls in your code? I'm thinking of either:

  • special gcc warning options.
  • some kind of lint tool detecting these calls.
like image 638
Roalt Avatar asked Dec 23 '22 10:12

Roalt


2 Answers

Lint can find deprecated things (-deprecated flag).

Coverity finds this kind of issue routinely with c and c++ codebases.

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.

like image 112
Will Avatar answered Dec 26 '22 11:12

Will


My first attempt would be a simple tool using grep (even though it may throw up false positives).

>> 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.

like image 38
paxdiablo Avatar answered Dec 26 '22 11:12

paxdiablo