Writing Coverity Custom checks only requires C and C++ programming skills. Once you compose an extension, it integrates directly into the Coverity analysis engine which executes the checks across your entire code base.
Example: Using path analysis to detect performance degradation caused by a blocking call
#include “extend-lang.h”
enum fun_state_t {
UNLOCKED = 0,
LOCKED = 1
};
START_EXTEND_CHECKER( block_check, int_store );
ANALYZE_TREE()
{
Fun locking_fun(“lock”);
Fun unlocking_fun(“unlock”);
Fun blocking_fun(“fopen”);
if ( MATCH(locking_fun) ) {
SET_STATE(LOCKED);
} else if ( MATCH(unlocking_fun) ) {
SET_STATE(UNLOCKED);
} else if ( MATCH(blocking_fun) ) {
if ( GET_STATE() == LOCKED ) ) {
COMMIT_ERROR(“Called fopen within a locking context.”);
}
}
}
END_EXTEND_CHECKER();
MAKE_MAIN( block_check )
Contact us to find out how Coverity Static Analysis can shorten your development cycles and help you deliver more reliable, secure software.
+1 (415) 321-5237 (International)
(800) 873-8193 (U.S. toll-free)