Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coverity. Configure to ignore certain sections of the source code

Tags:

coverity

Looking for a way to configure coverity to ignore certain code sections. For example let's say I have source code with func1 and func2. I don't want coverity to analyse func1, but I still want it to analyse func2. Is there a way to do that? Is there a special inline comment that I can add perhaps?

int func1(int* value)
{
   *value++;

  return 0;
}
int func2(int* value)
{
 *value--;

 return 0;
}
like image 326
TheLighthouse Avatar asked Sep 01 '25 20:09

TheLighthouse


1 Answers

You can exclude a section of C/C++ code using the __COVERITY__ preprocessor macro, which is defined by the Coverity compiler. For example, to exclude func1 but include func2 in the analysis, do something like:

#ifndef __COVERITY__           // <-- added
int func1(int* value)
{
   *value++;

  return 0;
}
#endif                         // <-- added

int func2(int* value)
{
 *value--;

 return 0;
}

Related:

  • Synopsys Community support question "Ignore specific function", which also describes using __COVERITY__.
  • Synopsys Support article "How to exclude the specific path or files from being analyzed", which describes the skip_file directive, which can be used to exclude entire files.
  • SO question "What preprocessor symbols does Coverity define for a build using 'cov-build'?", which it turns out is asking a similar question to this one, although that is not clear from the title (as it references a presumed solution rather than describing the problem), and hence I don't consider it a duplicate.
like image 136
Scott McPeak Avatar answered Sep 07 '25 02:09

Scott McPeak