You can similarly use all of the features in Code Analyzer with the codean command . This section is a short tutorial on how to use the codean command to catch new static code issues in your code, using the same sample program from OracleDeveloperStudio12.5-Samples.
Previous sections of this tutorial did not compile the sample4.c. Preview this file with the cat command.
$ cat sample_4.c
int another_new_umr()
{
int i;
if (i)
return 0;
else
return 1;
}
Notice that int i is uninitialized.
Compile the source and generate the static report.
On Oracle Solaris:
$ cc -g -xprevise main.c previse_1.c previse_all.c sample1.c sample2.c sample3.c
On Oracle Linux:
$ cc -xannotate -g -xprevise main.c previse_1.c previse_all.c sample1.c sample2.c sample3.c
Save the static report using the codean –-save option to a.out.
$ codean --save -s a.out
Recompile the sample application, this time including sample4.c.
On Oracle Solaris:
$ cc -g -xprevise *.c
On Oracle Linux:
$ cc -g -xannotate -xprevise *.c
This new function is never called from main,however it will introduce a new UMR error.
Use the –-whatisnew option to get a report on the newly added static issue.
$ codean --whatisnew -s a.out
STATIC report of a.out showing new issues:
Compare the latest results against a.out.analyze/history/2014.8.4.14.49.56...
ERROR 1 (UMR): accessing uninitialized data: i at:
another_new_umr() <sample_4.c : 4>
1: int another_new_umr()
2: {
3: int i;
4:=> if (i)
5: return 0;
PREVISE SUMMARY for a.out: 1 new error(s), 0 new warning(s), 0 new leak(s) in total
The following figure shows the HTML report on static code issues generated by codean.
For more information about codean, see Using the Code Analyzer Command-Line Tool (codean) in Oracle Developer Studio 12.5: Code Analyzer User’s Guide and the codean(1) man page.