Go to main content
Oracle® Developer Studio 12.6: Code Analyzer Tutorial

Exit Print View

Updated: June 2017

Using the codean Command-Line Tool

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 OracleDeveloperStudio-12.6-Samples.

  1. 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;
        return 1;

    Notice that int i is uninitialized.

  2. 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
  3. Save the static report using the codean –-save option to a.out.

    $ codean --save -s a.out
  4. 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.

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

image:codean generated HTML report for Static Code Issues, showing a new UMR                     error

For more information about codean, see Using the Code Analyzer Command-Line Tool (codean) in Oracle Developer Studio 12.6: Code Analyzer User’s Guide and the codean(1) man page.